CSS ::first-letter 伪元素
定义和用法
CSS ::first-letter
伪元素用于设置块级元素的第一个字母的样式。
注意:以下属性可以与 ::first-letter
一起使用:
- 所有字体属性
- 所有背景属性
- 所有外边距属性
- 所有内边距属性
- 所有边框属性
- 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
实例
选择并设置每个 <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 |
相关页面
教程:CSS 伪元素