IE瀏覽器CSS Hack速查表(IE6/7/8/9/10)

來源:互聯網
上載者:User


CSS Hack的原理是什麼

由於不同的瀏覽器對CSS的支援及解析結果不一樣,還由於CSS中的優先順序的關係。我們就可以根據這個來針對不同的瀏覽器來寫不同的CSS。

CSS Hack大致有3種表現形式,CSS類內部Hack、選取器Hack以及HTML頭部引用(if IE)Hack,CSS Hack主要針對IE瀏覽器。

類內部Hack:比如 IE6能識別底線”_”和星號” * “,IE7能識別星號” * “,但不能識別底線”_”,而firefox兩個都不能認識。等等

選取器Hack:比如 IE6能識別*html .class{},IE7能識別*+html .class{}或者*:first-child+html .class{}。等等

HTML頭部引用(if IE)Hack:針對所有IE:<!–[if IE]><!–您的代碼–><![endif]–>,針對IE6及以下版本:<!–[if lt IE 7]><!–您的代碼–><![endif]–>,這類Hack不僅對CSS生效,對寫在判斷語句裡面的所有代碼都會生效。

書寫順序,一般是將識別能力強的瀏覽器的CSS寫在後面。下面如何寫裡面說得更詳細些。

如何寫CSS Hack
比如要分辨IE6和firefox兩種瀏覽器,可以這樣寫:

 代碼如下 複製代碼

<style>
div{
background:green; /* for firefox */
*background:red; /* for IE6 */
}
</style>

我在IE6中看到是紅色的,在firefox中看到是綠色的。


IE6 CSS Hack


IE6 CSS Hack only

 代碼如下 複製代碼

/* For IE6 and earlier */
* html .demo{color:#090;}
.demo{_color:#090;}other IE6 CSS Hack

.demo{*color:#090;/* For IE7- */}
.demo{+color:#090;/* For IE7- */}
.demo{#color:#090;/* For IE7- */}
.demo{>color:#090;/* For IE7- */}
.demo{.color:#090;/* For IE7- */}
.demo{color:#0909;/* For IE6+ */}
.demo{[;color:#f00;];/* For IE7- and webkit */}
.demo{color:#0909;/* All IE */}

IE7 CSS Hack

 代碼如下 複製代碼

IE7 CSS Hack only

* + html .test{color:#ff0;}     /* For IE7 */other IE7 CSS Hack

.demo{*color:#090;/* For IE7- */}
.demo{+color:#090;/* For IE7- */}
.demo{#color:#090;/* For IE7- */}
.demo{>color:#090;/* For IE7- */}
.demo{.color:#090;/* For IE7- */}
.demo{color:#0909;/* For IE6+ */}
.demo{[;color:#f00;];/* For IE7- and webkit */}
.demo{color:#0909;/* All IE */}


IE8 CSS Hack

 代碼如下 複製代碼

IE8 CSS Hack only

.demo{color::#09F/}/* For IE8 */other IE8 CSS Hack

.demo{color:#09F;/*IE8+*/}
.demo{color:#0909;/* All IE */}

IE9 CSS Hack

IE9 CSS Hack only
暫未發現僅IE9能識別的CSS Hack;隨著IE10、IE11的出現網路上流傳的“IE9 CSS Hack only”已經失效。

 代碼如下 複製代碼

other IE9 CSS Hack

.demo{color:blue9;}  /* IE9+*/
.demo{color:#09F;/*IE8+*/}
.demo{color:#0909;/* All IE */}
@media screen and (min-width:0) {
    .demo{color:blue;}/* IE9 , IE10 ,IE11 rule sets go here */
}

IE10 CSS Hack
IE10 CSS Hack only

無

 代碼如下 複製代碼

other IE10 CSS Hack

.demo{color:blue9;}  /* IE9+*/
.demo{color:#09F;/*IE8+*/}
.demo{color:#0909;/* All IE */}

@media screen and (min-width:0) {
    .demo{color:blue;}/* IE9 , IE10 ,IE11 rule sets go here */
}
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
    .demo{color:blue;}/* IE10-specific styles go here */
}

總結,隨著IE的逐漸標準化,IE11和IE10可能很少用不到CSS Hack了。

聯繫我們

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