css中的content屬性怎么用?

css中的content屬性怎么用?很多人都不太了解,今天小編為了讓大家更加了解css中的content屬性,所以給大家總結(jié)了以下內(nèi)容,一起往下看吧。

在建德等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供做網(wǎng)站、網(wǎng)站設(shè)計 網(wǎng)站設(shè)計制作按需定制設(shè)計,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站制作,網(wǎng)絡(luò)營銷推廣,成都外貿(mào)網(wǎng)站建設(shè)公司,建德網(wǎng)站建設(shè)費用合理。

css中的content屬性怎么用?

content屬性一般用于::before、::after偽元素中,用于呈現(xiàn)偽元素的內(nèi)容。平時content屬性值我們用的最多的就是給個純字符,其實它還有很多值可供選擇。

1、插入純字符

<style>
    *{margin: 0;padding: 0;box-sizing: border-box;}
    li{list-style: none;}
    .content{
        position: relative;padding: 10px;
        border: 1px solid #666;margin: 10px;
    }
    .content.only-text::before{
        content: '插入純字符';
    }
</style>

<body>
    <h3>1、插入純字符</h3>
    <div class="content only-text"></div>
</body>

2、插入圖片

<style>
    *{margin: 0;padding: 0;box-sizing: border-box;}
    li{list-style: none;}
    .content{
        position: relative;padding: 10px;
        border: 1px solid #666;margin: 10px;
    }
    .content.fill-image::before{
        content: url('https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo_top_86d58ae1.png');
    }
</style>

<body>
    <h3>2、插入圖片</h3>
    <div class="content fill-image"></div>
</body>

3、插入元素屬性

<style>
    *{margin: 0;padding: 0;box-sizing: border-box;}
    li{list-style: none;}
    .content{
        position: relative;padding: 10px;
        border: 1px solid #666;margin: 10px;
    }
    .content.fill-dom-attr::before{
        content: attr(data-title);
    }
</style>

<body>
    <h3>3、插入元素屬性</h3>
    <div class="content fill-dom-attr" data-title="我是.fill-dom-attr元素的 data-title 屬性值"></div>
</body>

4、插入當(dāng)前元素編號(即當(dāng)前元素索引)

這個特性可用于活動頁面的規(guī)則介紹。

<style>
    *{margin: 0;padding: 0;box-sizing: border-box;}
    li{list-style: none;}
    .content{
        position: relative;padding: 10px;
        border: 1px solid #666;margin: 10px;
    }
    .fill-dom-index li{
        position: relative;
        /* 給計數(shù)器加器起個名字,它只會累加 li 標(biāo)簽的索引,li元素中間的div并不會理會 */
        counter-increment: my;
    }
    .fill-dom-index li div::before{
        /* 使用指定名字的計算器 */
        content: counter(my)'- ';
        color: #f00;
        font-weight: 600;
    }
</style>

<body>
    <h3>4、插入當(dāng)前元素編號(即當(dāng)前元素索引)</h3>
    <div class="content fill-dom-index">
        <ul>
            <li><div>我是第1個li標(biāo)簽</div></li>
            <div>我是li標(biāo)簽中的第1個div標(biāo)簽</div>
            <li><div>我是第2個li標(biāo)簽</div></li>
            <li><div>我是第3個li標(biāo)簽</div></li>
            <div>我是li標(biāo)簽中的第2個div標(biāo)簽</div>
            <li><div>我是第4個li標(biāo)簽</div></li>
            <li><div>我是第5個li標(biāo)簽</div></li>
        </ul>
    </div>
</body>

5、插入當(dāng)前元素編號(指定種類)

<style>
    *{margin: 0;padding: 0;box-sizing: border-box;}
    li{list-style: none;}
    .content{
        position: relative;padding: 10px;
        border: 1px solid #666;margin: 10px;
    }
    .fill-dom-index2 li{
        position: relative;
        counter-increment: my2;
    }
    .fill-dom-index2 li div::before{
        /* 第二個參數(shù)為list-style-type,可用值見: http://www.w3school.com.cn/cssref/pr_list-style-type.asp*/
        content: counter(my2,lower-latin)'- ';
        color: #f00;
        font-weight: 600;
    }
</style>

<body>
    <h3>5、插入當(dāng)前元素編號(指定種類)</h3>
    <div class="content fill-dom-index2">
        <ul>
            <li><div>我是第1個li標(biāo)簽</div></li>
            <div>我是li標(biāo)簽中的第1個div標(biāo)簽</div>
            <li><div>我是第2個li標(biāo)簽</div></li>
            <li><div>我是第3個li標(biāo)簽</div></li>
            <div>我是li標(biāo)簽中的第2個div標(biāo)簽</div>
            <li><div>我是第4個li標(biāo)簽</div></li>
            <li><div>我是第5個li標(biāo)簽</div></li>
        </ul>
    </div>
</body>

關(guān)于css中的content屬性怎么用就分享到這里了,當(dāng)然并不止以上和大家分析的辦法,不過小編可以保證其準(zhǔn)確性是絕對沒問題的。希望以上內(nèi)容可以對大家有一定的參考價值,可以學(xué)以致用。如果喜歡本篇文章,不妨把它分享出去讓更多的人看到。

當(dāng)前題目:css中的content屬性怎么用?
本文鏈接:http://muchs.cn/article40/gpjheo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機、微信小程序、網(wǎng)頁設(shè)計公司、、全網(wǎng)營銷推廣商城網(wǎng)站

廣告

聲明:本網(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)

小程序開發(fā)