css中!important的用法總結

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   io   ar   div   

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</title> <style> <!-- !important只有Ie7.0和firefox可以識別,但是Ie6.0不能成功應用.!important提升優先順序(或看成強制重定義--> <!--  !important是CSS1就定義的文法,作用是提高指定樣式規則的應用優先權(參見:W3.org的解釋)。文法格式 { sRule!important } ,即寫在定義的最後面,例如:box { color:red !important; }   假如我們定義一個這樣的樣式:      #box { background-color: #ffffff !important; background-color: #000000; }   那麼在支援該文法的瀏覽器,如Firefox、Opera中,能夠理解!important的優先順序,背景顯示#cccccc顏色,而在IE中則顯示#000000.能說它“不認識、不支援”! --> #box div { color:red; } .important_false { color:blue; } .important_true { color:blue !important; } #box2 { background-color: #cccccc !important; background-color: #000000; } <!-- firefox: 下面這段如果放在最上面,則是紅色的, 如果放在最下面則是blue。說明如果放在最上面,#box div覆蓋了#idColor,這時是id的優先順序。而.important_false的class優先順序小於id,沒有覆蓋掉#box div。   如果放在最下面,則#idColor沒有覆蓋.important_false。 如果不設定id="idColor", 則是blue。說明.important_false 覆蓋掉了#box div   IE7:   #idColor放在最下面,是紅色的。放在最下面也是紅色的,去掉id屬性。也是紅色的。說明都沒覆蓋#box div。 --> #idColor { color:gray; } </style> </head> <body> <div id="box">   <div class="important_false" id="idColor">這一行末使用important。class的優先順序小於id的優先順序。IE7是紅色,firefox是藍色。</div>   <div class="important_true" >這一行使用了important</div> </div> <div id="box2"> 在不同的瀏覽器下,這行字的色應該不同!IE7,Firefox是紅色。IE6是藍色</div> </body> </html> 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.