CSS :first-line伪元素
描述
伪元素:first-line用于给文本的第一行添加特殊效果。
以下属性适用于此伪元素:
- 字体属性
- 颜色属性
- 背景属性
- 字间距
- 字母间距
- 文本装饰
- 垂直对齐
- 文本转换
- 行高
- 清除
示例
下面的示例演示了如何使用伪元素:first-line来给文档中元素的第一行添加特殊效果。
<html>
<head>
<style type = "text/css">
p:first-line { text-decoration: underline; }
p.noline:first-line { text-decoration: none; }
</style>
</head>
<body>
<p class = "noline">
This line would not have any underline because this belongs
to nline class.
</p>
<p>
The first line of this paragraph will be underlined as defined in the
CSS rule above. Rest of the lines in this paragraph will remain normal.
This example shows how to use :first-line pseduo element to give effect
to the first line of any HTML element.
</p>
</body>
</html>
以下内容将产生以下黑色链接 −