溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

CSS3中如何使用content屬性

發(fā)布時間:2022-03-01 14:41:03 來源:億速云 閱讀:193 作者:小新 欄目:web開發(fā)

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

css屬性【content】用來和:after:before偽元素一起使用,在對象前或后顯示內容。

content的取值:

normal:默認值。表現與none值相同

none:不生成任何值。<attr>:插入標簽屬性值<url>:使用指定的絕對或相對地址插入一個外部資源(圖像,聲頻,視頻或瀏覽器支持的其他任何資源)<string>:插入字符串

counter(name):使用已命名的計數器

counter(name,list-style-type):使用已命名的計數器并遵從指定的list-style-type屬性

counters(name,string):使用所有已命名的計數器

counters(name,string,list-style-type):使用所有已命名的計數器并遵從指定的list-style-type屬性

no-close-quote:并不插入quotes屬性的后標記。但增加其嵌套級別

no-open-quote:并不插入quotes屬性的前標記。但減少其嵌套級別

close-quote:插入quotes屬性的后標記

open-quote:插入quotes屬性的前標記

這里比較不好理解的取值就是:counter(name)這些;

下面主要總結一下這塊,最后會給出各個取值的demo,

比如我有如下html結構:

<ul>

<li>這個是A計劃</li>

<li>這個是A計劃</li>

<li>這個是A計劃</li>

<li>這個是A計劃</li>

<li>這個是A計劃</li></ul>

我要在每個li的后面加上當前liindex】值:

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就是csslist-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)拓展應用:</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屬性”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI