温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

css3给文字加描边的方法

发布时间:2020-09-26 11:26:49 来源:亿速云 阅读:166 作者:小新 栏目:web开发

这篇文章主要介绍css3给文字加描边的方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

首先我们来通过简单的代码示例介绍一下css3中的text-stroke属性给文字添加描边效果的实现方法。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>文字描边</title>
		<style type="text/css">
			.demo {
				font-family: Verdana;
				font-size: 30px;
				font-weight: bold;
			}
			.stroke {
				-webkit-text-stroke: 1px red;
			}
		</style>
	</head>

	<body>
		<div class="demo">
			<p>测试文字,没有添加描边</p>
			<p class="stroke">测试文字,添加了字体描边</p>
		</div>
	</body>
</html>

效果图:

css3给文字加描边的方法

从示例,我们可以看出,css3通过设置 text-stroke:1px red;就可以在文字上添加1px的红色描边样式。由此,可以知道text-stroke属性是通过width值来设置或检索对象中的文字的描边厚度,通过color值来设置或检索对象中的文字的描边颜色。

text-stroke属性的基本语法:

text-stroke:width  || color ;

值得注意的是:text-stroke属性只能在有webkit内核的Safari和Chrome等浏览器中被支持使用,使用时要加前缀:-webkit-。

css3给文字加描边的方法

下面我们用text-stroke属性来实现一个好看的文字描边效果。

代码示例:

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>文字描边</title>
		<style type="text/css">
			.demo {
				font-family: Verdana;
				font-size: 50px;
				font-weight: bold;
			}
			
			.stroke {
				-webkit-text-fill-color: transparent;/*文字的填充色*/
				-webkit-text-stroke: 2px #f44336;
				font-style: italic;
			}
		</style>
	</head>

	<body>
		<div class="demo">
			<p class="stroke">亿速云--文字描边</p>
		</div>
	</body>

</html>

通过-webkit-text-fill-color: transparent;设置文字的填充色为透明,通过font-style: italic;设置文字倾斜,在通过text-stroke属性设置描边的厚度与好看的颜色,一个好看的艺术字就实现了!

以上是css3给文字加描边的方法的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI