css3怎么改首字母颜色-LMLPHP

本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

css3修改首字母颜色

实现思想:

  • 使用“:first-letter”选择器选中元素的首字母

  • 使用color属性给选中的字母修改文本颜色。

    Color属性可以指定文本的颜色。

实现代码:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style type="text/css">
			.first {
				width: 200px;
				height: 100px;
				border: 1px solid red;
			}

			.first p::first-letter {
				color: red;
			}
		</style>
	</head>
	<body>
		<div class="first">
			<p>aksadjklahkljasklf</p>
		</div>

	</body>
登录后复制

css3怎么改首字母颜色-LMLPHP

扩展知识:

:first-letter选择器可以使用以下属性:

  • font

  • color

  • background

  • margin

  • padding

  • border

  • text-decoration

  • vertical-align (only if float is 'none')

  • text-transform

  • line-height

  • float

  • clear

(学习视频分享:css视频教程web前端

以上就是css3怎么改首字母颜色的详细内容,更多请关注Work网其它相关文章!

08-28 06:43