小編給大家分享一下CSS3中如何使用content屬性,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比臺山網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式臺山網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋臺山地區(qū)。費用合理售后完善,十年實體公司更值得信賴。
css屬性【content】用來和:after及:before偽元素一起使用,在對象前或后顯示內(nèi)容。
content的取值:
normal:默認(rèn)值。表現(xiàn)與none值相同
none:不生成任何值。<attr>:插入標(biāo)簽屬性值<url>:使用指定的絕對或相對地址插入一個外部資源(圖像,聲頻,視頻或瀏覽器支持的其他任何資源)<string>:插入字符串
counter(name):使用已命名的計數(shù)器
counter(name,list-style-type):使用已命名的計數(shù)器并遵從指定的list-style-type屬性
counters(name,string):使用所有已命名的計數(shù)器
counters(name,string,list-style-type):使用所有已命名的計數(shù)器并遵從指定的list-style-type屬性
no-close-quote:并不插入quotes屬性的后標(biāo)記。但增加其嵌套級別
no-open-quote:并不插入quotes屬性的前標(biāo)記。但減少其嵌套級別
close-quote:插入quotes屬性的后標(biāo)記
open-quote:插入quotes屬性的前標(biāo)記
這里比較不好理解的取值就是:counter(name)這些;
下面主要總結(jié)一下這塊,最后會給出各個取值的demo,
比如我有如下html結(jié)構(gòu):
<ul>
<li>這個是A計劃</li>
<li>這個是A計劃</li>
<li>這個是A計劃</li>
<li>這個是A計劃</li>
<li>這個是A計劃</li></ul>
我要在每個li的后面加上當(dāng)前l(fā)i【index】值:
ul li{
counter-increment:index;
}
ul li:after{
content:'統(tǒng)計:'counter(index);
display:block;
line-height:35px;
}
解釋:
count(name)這里的name,必須要提前指定好,否則所有的值都將是0;
count(name,list-style-type)這里的list-style-type就是css中l(wèi)ist-style-type屬性的取值;
下面給出完整DEMO
<!DOCTYPE html><html><head><meta charset="utf-8"><title>CSS content</title><meta name="author" content="phpstudy.net"><meta name="copyright" content="www.phpstudy.net"><style>
.string p:after {
margin-left: -16px;
background: #fff;
content: "支持";
color: #f00;}
.attr p:after {
content: attr(title);}
.url p:before {
content: url(https://pic.cnblogs.com/avatar/779447/20160817152433.png);
display: block;}
.test ol {
margin: 16px 0;
padding: 0;
list-style: none;}
.counter1 li {
counter-increment: testname;}
.counter1 li:before {
content: counter(testname)":";
color: #f00;
font-family: georgia,serif,sans-serif;}
.counter2 li {
counter-increment: testname2;}
.counter2 li:before {
content: counter(testname2,lower-roman)":";
color: #f00;
font-family: georgia,serif,sans-serif;}
.counter3 ol ol {
margin: 0 0 0 28px;}
.counter3 li {
padding: 2px 0;
counter-increment: testname3;}
.counter3 li:before {
content: counter(testname3,float)":";
color: #f00;
font-family: georgia,serif,sans-serif;}
.counter3 li li {
counter-increment: testname4;}
.counter3 li li:before {
content: counter(testname3,decimal)"."counter(testname4,decimal)":";}
.counter3 li li li {
counter-increment: testname5;}
.counter3 li li li:before {
content: counter(testname3,decimal)"."counter(testname4,decimal)"."counter(testname5,decimal)":";}</style></head><body><ul>
<li>
<strong>string:</strong>
<p>你的瀏覽器是否支持content屬性:否</p>
</li>
<li>
<strong>attr:</strong>
<p title="如果你看到我則說明你目前使用的瀏覽器支持content屬性"></p>
</li>
<li>
<strong>url():</strong>
<p>如果你看到我的頭像圖片則說明你目前使用的瀏覽器支持content屬性</p>
</li>
<li>
<strong>counter(name):</strong>
<ol>
<li>列表項</li>
<li>列表項</li>
<li>列表項</li>
</ol>
</li>
<li>
<strong>counter(name,list-style-type):</strong>
<ol>
<li>列表項</li>
<li>列表項</li>
<li>列表項</li>
</ol>
</li>
<li>
<strong>counter(name)拓展應(yīng)用:</strong>
<ol>
<li>列表項
<ol>
<li>列表項
<ol>
<li>列表項</li>
<li>列表項</li>
</ol>
</li>
<li>列表項</li>
</ol>
</li>
<li>列表項
<ol>
<li>列表項</li>
<li>列表項</li>
</ol>
</li>
<li>列表項
<ol>
<li>列表項</li>
<li>列表項</li>
</ol>
</li>
</ol>
</li></ul></body></html>
以上是“CSS3中如何使用content屬性”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
新聞名稱:CSS3中如何使用content屬性
文章位置:http://www.chinadenli.net/article12/pissdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、定制網(wǎng)站、品牌網(wǎng)站設(shè)計、App開發(fā)、品牌網(wǎng)站建設(shè)、移動網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)