CSS ::first-letter 伪元素
示例
选择每个 <p> 元素的第一个字母并设置其样式
p::first-letter {
font-size: 200%;
font-weight: bold;
color: #8A2BE2;
}
自己动手试一试 »
定义和用法
::first-letter
伪元素用于为块级元素的第一个字母设置样式。
注意: 以下属性可与 ::first-letter 一起使用
- 所有字体属性
- 所有 background 属性
- 所有 margin 属性
- 所有 padding 属性
- 所有 border 属性
- color
- text-decoration
- text-shadow
- letter-spacing
- word-spacing
- text-transform
- text-decoration-color
- text-decoration-line
- text-decoration-style
- box-shadow
- vertical-align (仅当 float 为 'none' 时)
- line-height
- float
版本 | CSS1 |
---|
浏览器支持
表中数字表示首次完全支持此伪元素的浏览器版本。
伪元素 | |||||
---|---|---|---|---|---|
::first-letter | 1.0 | 9.0 | 1.0 | 1.0 | 7.0 |
CSS 语法
相关页面
CSS 教程:CSS 伪元素