针对IE的CSSHack合集
做WEB前端不得不了解的就是CSSHack,帮助我们兼容各个浏览器。原来一直没有整理,只是用一些常用的,今天把他整理出来,以便以后更方便的学习使用。
1 select { 2 /*普通的CSS写法*/ 3 color: #f99; 4 /*兼容IE8/9的CSS写法*/ 5 color: #9f9\0; 6 /*兼容IE9的CSS写法*/ 7 color: #99f\9\0; 8 /*兼容IE6/7的CSS写法*/ 9 *color: #ff9; 10 /*兼容IE6的CSS写法*/ 11 _color: #f9f; 12 }
在这里,CSSHack的书写顺序就非常重要了,如果顺序写错,可能会导致部分CSS无法工作。
个人不倾向于这种写法,因为会污染CSS文件,对于有强迫症的我,习惯把CSSHack提出来。
1 /*普通的CSS写法*/ 2 select { color: #f99; } 3 /*兼容IE6的CSS写法*/ 4 * html select { color: #f9f; } 5 /*兼容IE7的CSS写法*/ 6 *:first-child + html select { color: #ff9; } 7 /*兼容IE7+的CSS写法*/ 8 html > body select { color: #99f; } 9 /*兼容IE8+的CSS写法*/ 10 html > /**/ body select { color: #9f9; } 11 /*兼容IE9+的CSS写法*/ 12 :root select { color: #999; }