IE各版本CSS Hack(兼容性處理)語法速查表

CSS HTML Safari 教育 IT豆豆 2017-06-18

為了兼容IE各個版本,需要在CSS中添加額外的代碼,比如以前常用的_width。之所以工作,是因為瀏覽器會忽略不能解析的樣式規則,因此舉個例子來說,把_width寫在width下面,對於非IE瀏覽器會解析到width,而對於IE6來說,會用_width覆蓋前面的width規則,從而達到針對IE6瀏覽器的兼容。對於IE其他版本(6~11),也存在同樣的兼容性處理方法。

IE各版本CSS Hack(兼容性處理)語法速查表

下面是一個速查表:

div {

property:value\0; /* ie 8/9*/

property:value\9\0; /* ie 9*/

*property:value; /* ie 7*/

_property:value; /* ie 6*/

}

IE 6

* html .ie6 {property:value;}

or

.ie6 { _property:value;}

IE 7

*+html .ie7 {property:value;}

or

*:first-child+html .ie7 {property:value;}

IE 6 and 7

@media screen\9 {

.ie67 {property:value;}}

or

.ie67 { *property:value;}

or

.ie67 { #property:value;}

IE 6, 7 and 8

@media \0screen\,screen\9 {

.ie678 {property:value;}}

IE 8

html>/**/body .ie8 {property:value;}

or

@media \0screen {

.ie8 {property:value;}}

IE 8 Standards Mode Only

.ie8 { property /*\**/: value\9 }

IE 8,9 and 10

@media screen\0 {

.ie8910 {property:value;}}

IE 9 only

@media screen and (min-width:0\0) and (min-resolution: .001dpcm) {

// IE9 CSS

.ie9{property:value;}}

IE 9 and above

@media screen and (min-width:0\0) and (min-resolution: +72dpi) {

// IE9+ CSS

.ie9up{property:value;}}

IE 9 and 10

@media screen and (min-width:0\0) {

.ie910{property:value\9;} /* backslash-9 removes ie11+ & old Safari 4 */}

IE 10 only

_:-ms-lang(x), .ie10 { property:value\9; }

IE 10 and above

_:-ms-lang(x), .ie10up { property:value; }

or

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {

.ie10up{property:value;}}

IE 11 (and above..)

_:-ms-fullscreen, :root .ie11up { property:value; }