CSS ::first-letter 伪元素
定义和用法
CSS ::first-letter 伪元素用于设置块级元素的第一个字母的样式。
注意:以下属性可以与 ::first-letter 一起使用:
- 所有字体属性
- 所有背景属性
- 所有外边距属性
- 所有内边距属性
- 所有边框属性
colortext-decorationtext-shadowletter-spacingword-spacingtext-transformtext-decoration-colortext-decoration-linetext-decoration-stylebox-shadowvertical-align(仅当float为none时)line-heightfloat
实例
选择并设置每个 <p> 元素的第一个字母的样式:
p::first-letter {
font-size: 200%;
font-weight: bold;
color: #8A2BE2;
}
CSS 语法
::first-letter {
css declarations;
}
技术细节
| 版本: | CSS1 |
|---|
浏览器支持
表格中的数字指定了完全支持该伪元素的首个浏览器版本。
| Chrome | Edge | Firefox | Safari | Opera |
|---|---|---|---|---|
| 1.0 | 9.0 | 1.0 | 1.0 | 7.0 |