亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    了解CSS的選擇器優(yōu)先級和!important權(quán)重

    了解CSS的選擇器優(yōu)先級和!important權(quán)重

    推薦:css視頻教程

    CSS中的選擇器優(yōu)先級與!important權(quán)重

    • .class選擇器要高于標(biāo)簽選擇器。
    • #id選擇器要高于.class選擇器。
    • 標(biāo)簽選擇器是優(yōu)先級最低的選擇器。
    • !important的屬性它的權(quán)重值優(yōu)先級最高的,大于所有的選擇器。

    標(biāo)簽選擇器和.class選擇器

    讓我們進(jìn)入標(biāo)簽選擇器和.class選擇器誰的優(yōu)先級高實踐,實踐內(nèi)容如:將HTML頁面中的h2標(biāo)簽設(shè)置文本顏色。

    代碼塊

    <!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <meta http-equiv="X-UA-Compatible" content="ie=edge">     <title>優(yōu)先級</title>     <style>         h2{            color: red; /*紅色*/        }        .box{             color: springgreen; /*綠色*/        }     </style> </head>    <body>     <h2 class="box">微笑是最初的信仰</h2> </body> </html>

    結(jié)果圖

    了解CSS的選擇器優(yōu)先級和!important權(quán)重

    .class選擇器和id選擇器

    讓我們進(jìn)入.class選擇器和id選擇器誰的優(yōu)先級高實踐,實踐內(nèi)容如:將HTML頁面中的h2標(biāo)簽設(shè)置文本顏色。

    代碼塊

    <!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <meta http-equiv="X-UA-Compatible" content="ie=edge">     <title>優(yōu)先級</title>     <style>        h2{            color: red; /*紅色*/        }        .box{             color: springgreen; /*綠色*/        }        #box{            color:blue; /*藍(lán)色*/        }     </style> </head>    <body>    <h2 class="box" id="box">微笑是最初的信仰</h2> </body> </html>

    結(jié)果圖

    了解CSS的選擇器優(yōu)先級和!important權(quán)重

    !important權(quán)重使用

    現(xiàn)在我們知道了標(biāo)簽選擇器優(yōu)先級最低,那么筆者將標(biāo)簽選擇器添加!important屬性呢,誰的優(yōu)先級更高呢?
    !important權(quán)重使用格式如下:

    color: red !important; /*紅色*/

    注意:屬性:值 !important屬性值用空格隔開即可。

    讓我們進(jìn)入 !important屬性使用實踐,看看!important屬性威力有多大哈。

    代碼塊

    <!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <meta http-equiv="X-UA-Compatible" content="ie=edge">     <title>!important使用</title>     <style>        h2{            color: red !important; /*紅色*/        }        .box{             color: springgreen; /*綠色*/        }        #box{            color:blue; /*藍(lán)色*/        }     </style> </head>    <body>    <h2 class="box" id="box">微笑是最初的信仰</h2> </body> </html>

    結(jié)果圖

    了解CSS的選擇器優(yōu)先級和!important權(quán)重

    總結(jié)

    優(yōu)先級從低到高如:標(biāo)簽選擇器、.class選擇器、#id選擇器、!important屬性

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號