- HTML中文网
- 联系QQ:88526
- QQ交流群

- 微信公众号

:before 选择器
定义和用法
:before 选择器向选定的元素前插入内容。
使用content 属性来指定要插入的内容。
浏览器支持
表格中的数字表示支持该属性的第一个浏览器版本号。
选择器 | ![]() | ![]() | ![]() | ![]() | ![]() |
:before | 4.0 | 9.0 部分从8.0 | 3.5 | 3.1 | 7.0 部分从 4.0 |
注意: :before在IE8中运行,必须声明<!DOCTYPE>
每个 <p>元素之前插入内容、并设置所插入内容的样式:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style> p:before{ content:"标题"; background-color:yellow; color:red; font-weight:bold; } </style> </head> <body> <div> <p>1、测试文本!</p> <p>2、测试文本!</p> </div> </body> </html>
点击 "运行实例" 按钮查看在线实例
效果图:
推荐手册