Css中!important的用法

來源:互聯網
上載者:User

標籤:注意   技術分享   box   char   tca   定義   als   .com   type   

!important為開發人員提供了一個增加樣式權重的方法。應當注意的是!important是對整條樣式的聲明,包括這個樣式的屬性和屬性值

<!DOCTYPE HTML><html><head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">    <title>測試!Important</title></head><style type="text/css">    #Box div    {        color: red;    }    .important_false    {        color: blue;    }    .important_true    {        color: blue !important;    }</style><body>    <div id="Box">        <div class="important_false">            這一行末使用important</div>        <div class="important_true">            這一行使用了important</div>    </div></body></html>

效果:

CSS代碼第一行設定了box裡面所有div中字型色為紅色,第二行和第三行都用class重新定義了自身div的字型色為藍色,

不同的是,第二行未使用!important,而第三行使用了!

總結:

第一行字型顏色是紅色,可以證明,css樣式設定中,id的優先順序大於class,這行字還是紅色。

第二行字型顏色是藍色,可以證明,!important的優先順序最高,important_true的css樣式生效,這行字變為了藍色!


特別說明:

!important在IE6中是不被識別的,例:

.testClass{     color:blue !important; 
    color:red;}

這種寫法在IE6下是識別不到的,.testCalss最後顯示為紅色,但也可以通過更改下寫法讓IE6識別到!important

.testClass{     color:blue !important; } .testClass{     color:red; }

 


Css中!important的用法

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.