**单冒号(:)用于CSS3伪类,双冒号(::)用于CSS3伪元素,不过浏览器须要同时支持旧的已经存在的伪元素写法,
好比:first-line、:first-letter、:before、:after等,单冒号(:)兼容性更好**html
div::after{ content: "普通字符串"; content: attr(父元素的html属性名称); content: url(图片、音频、视频等资源的url); /* 使用unicode字符集,采用4位16进制编码,但不一样的浏览器显示存在差别,并且移动端识别度更差*/ content: "\21e0"; /* content的多个值能够任意组合,各部分经过空格分隔 */ content: "'" attr(title) "'"; /* 自增计数器,用于插入数字/字母/罗马数字编号 */ content: counter(<identifier>, <list-style-type>); /* 以父附属元素的qutoes值做为content的值*/ content: open-quote | close-quote | no-open-quote | no-close-quote; }
content:"string",或content:none不插入内容浏览器
h1::after{ content:"h1后插入内容" } h2::after{ content:none }
<p class="phoneNumber">13900001390</p> .phoneNumber::before{ content:'\260E'; font-size: 16px; }
content属性也能够直接在元素前/后插入图片ide
h3::after{ content:url(http://ido321.qiniudn.com/wp-content/themes/yusi1.0/img/new.gif) }
content属性能够直接利用attr获取元素的属性,将其插入到对应位置。编码
<a href="http:///www.ido321.com">这是连接 </a> a:after{ content:attr(href); }
counter 调用计数器,能够不使用列表元素实现序号功能。
counter 要配合 counter-increment 和 counter-reset属性使用。url
content: counter(<identifier>, <list-style-type>); <list-style-type>: disc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-greek | lower-latin | upper-latin | armenian | georgian | lower-alpha | upper-alpha
<h1>大标题</h1> <h2>中标题</h2> <h3>小标题</h3> <h3>小标题</h3> <h2>中标题</h2> <h3>小标题</h3> <h3>小标题</h3> <h1>大标题</h1> <h2>中标题</h2> <h3>小标题</h3> <h3>小标题</h3> <h2>中标题</h2> <h3>小标题</h3> <h3>小标题</h3> h1::before{ content:counter(h1)'.'; } h1{ counter-increment:h1; counter-reset:h2; } h2::before{ content:counter(h1) '-' counter(h2); } h2{ counter-increment:h2; counter-reset:h3; margin-left:40px; } h3::before{ content:counter(h1) '-' counter(h2) '-' counter(h3); } h3{ counter-increment:h3; margin-left:80px; }
<h1>大标题</h1> h1{ quotes:"(" ")"; /*利用元素的quotes属性指定文字符号*/ } h1::before{ content:open-quote; } h1::after{ content:close-quote; }
<h2>中标题</h2> h2{ quotes:"\"" "\""; /*添加双引号要转义*/ } h2::before{ content:open-quote; } h2::after{ content:close-quote; }