css3给文字加描边的方法

这篇文章主要介绍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给文字加描边的方法的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!