[css] !important 控制樣式優先順序

來源:互聯網
上載者:User

先看看問題吧:



查看樣式:



當選中狀態,background-size 的屬性被覆蓋掉了,查看樣式屬性並沒有發現有什麼地方重定義。


當直接添加background-size 後,生效。



用其它同事的chrome訪問,發現展現沒有問題,初步判斷可能是chrome版本的問題,又測試了幾個chrome,果然



chrome 21.0.1180 對background渲染有不同,當重定義background屬性後,會把原有的background屬性,包括background-size 等全部覆蓋。


兩種解決方案:

1. 重定義的background添加上 background-size 等屬性

2. 在原有background-size 屬性添加 !important。 (高端瀏覽器支援,意思是比內聯style 優先順序還要高)

如:

background-size: 40px 50px !important;


顯示ok:




相關文章

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.