content
本页内容
CSS content 属性
以下实例将在每个链接后的括号内加上网址(href 属性):
示例
a:after
{
content: " (" attr(href) ")";
}
属性定义及使用说明
content 属性与 :before 及 :after 伪元素配合使用,来插入内容。
默认值: | normal |
继承: | no |
版本: | CSS2 |
JavaScript 语法: | object.style.content="url(beep.wav)" |
浏览器支持
表格中的数字表示支持该属性的第一个浏览器版本号。
属性 | Chrome | Internet Explorer / Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
content | 1.0 | 8.0 | 1.0 | 1.0 | 4.0 |
content 语法与属性值
语法格式:
content: normal|none|counter|attr|string|open-quote|close-quote|no-open-quote|no-close-quote|url|initial|inherit;
值 | 说明 | 实例 |
---|---|---|
none | 设置 content 为空值。 |
|
normal | 在 :before 和 :after 伪类元素中会被视为 none,即也是空值。 |
|
counter | 设定计数器,格式可以是 counter(name) 或 counter(name,style) 。产生的内容是该伪类元素指定名称的最小范围的计数;格式由style指定(默认是'decimal'——十进制数字) |
|
attr(attribute) | 将元素的 attribute 属性以字符串形式返回。。 |
|
string | 设置文本内容 |
|
open-quote | 设置前引号 |
|
close-quote | 设置后引号 |
|
no-open-quote | 移除内容的开始引号 |
|
no-close-quote | 移除内容的闭合引号 |
|
url(url) | 设置某种媒体(图像,声音,视频等内容)的链接地址 |
|
inherit | 指定的 content 属性的值,应该从父元素继承 |
更多实例
相关文章
CSS 参考手册: :before 伪元素
CSS 参考手册: :after 伪元素