语法:
content : normal | string | attr() | uri() | counter()
取值:
- normal:
- 默认值。
- string:
- 插入文本内容。
- attr():
- 插入元素的属性值。
- uri():
- 插入一个外部资源(图像,声频,视频或浏览器支持的其他任何资源)。
- counter():
- 计数器,用于插入排序标识。
说明:
content用于插入生成内容;
content属性与 :before 及 :after 伪元素配合使用,将生成内容放在一个元素内容的前面或后面。
兼容性:
| 类型 | Internet Explorer |
Firefox |
Chrome |
Opera |
Safari |
|---|---|---|---|---|---|
| 版本 | (×)IE6 | (×)Firefox 2.0 | (×)Chrome 1.0.x | (×)Opera 9.63 | (√)Safari 3.1 |
| (×)IE7 | (√)Firefox 3.0 | (×)Chrome 2.0.x | (√)Safari 4 | ||
| (√)IE8 | (√)Firefox 3.5 | ||||
示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="utf-8" />
<meta name="robots" content="all" />
<meta name="author" content="Tencent-ISRD" />
<meta name="Copyright" content="Tencent" />
<title>content</title>
<style type="text/css">
.example { width:400px; height:50px; line-height:50px; overflow:hidden; text-align:center; color:#FF0000; border:#993300 solid 1px; }
#example_01:before { content:"您使用的浏览器支持content属性"; }
</style>
</head>
<body>
<div id="example_01" class="example"></div>
</body>
</html>
Internet Explorer
Firefox
Chrome
Opera
Safari