css中使用!important優先順序最高問題

來源:互聯網
上載者:User

我們都知道在css屬性在不同的地方有不同的優先順序,但是我們可以在css定義中的用!important限定的定義最高優先順序。

下面我通過四種情況做個執行個體:

下面是執行個體代碼代碼裡有對應的說明:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title><style type="text/css">.p1{color:blue;/*<span style="font-family:";">1</span>沒加important 顯示為紅色   */}}.p2{color:blue;color:red!important;/*2加上了important屬性優先順序高 顯示為紅色   */}.p3{color:red!important;color:blue;/*3但是這種情況下在ie6一下ie版本會顯示為藍色但是在其他瀏覽器都顯示為紅色  */}/*4為瞭解決ie6及一下版本的相容 把樣式分開寫 important的優先順序高 顯示為紅色 */.p4{color:red!important;}.p4{color:blue;}</style></head><body><p class="p1">1沒加important</p><p class="p2">2加了important屬性</p><p class="p3">3IE6及一下版本識別不出來</p><p class="p4">4解決ie6及一下版本的相容問題</p></body></html>
下面是測試結果:

在ie6顯示結果


在其他瀏覽器及ie6以上顯示





相關文章

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.