CSS ::after 选择器
实例
在每个 <p> 元素的内容之后插入新内容:
<!DOCTYPE html><html><head><style>p::after {content: " - 记住";}</style></head><body><p>我的名字是唐老鸭</p><p>我住在 Ducksburg</p></body></html>
浏览器支持
表格中的数字注明了完全支持该属性的首个浏览器版本。
| 选择器 | |||||
|---|---|---|---|---|---|
| ::after | 4.0 | 9.0 | 3.5 | 3.1 | 7.0 |
注释:对于 IE8 及更早版本的浏览器中的 element>element,必须声明 <!DOCTYPE>。
定义和用法
:after 选择器在被选元素的内容后面插入内容。
请使用 content 属性来指定要插入的内容。
实例
在每个 <p> 元素后面插入内容,并设置所插入内容的样式:
<!DOCTYPE html><html><head><style>p::after {content: " - Remember this";background-color: yellow;color: red;font-weight: bold;}</style></head><body><h2>::after 选择器的 demo</h2><p>我的名字是唐老鸭</p><p>我住在 Ducksburg</p></body></html>
相关页面
CSS 教程:CSS 伪元素
CSS 选择器参考手册:CSS :before 选择器