我想为ie8使用一些不同的CSS,但只保留一个CSS文件.谁能告诉我这个最好的“黑客”是什么?是的,我知道黑客不好,但我想保留一个CSS文件,至少目前.
例如,在非IE8浏览器中,我希望浏览器看到这个:
- div.content_header_heading {
- background: -moz-linear-gradient(top,#cccccc 0%,#eeeeee 35%,#eeeeee 65%,#cccccc 100%); /* FF3.6+ */
- background: -webkit-gradient(linear,left top,left bottom,color-stop(0%,#cccccc),color-stop(35%,#eeeeee),color-stop(65%,color-stop(100%,#cccccc)); /* Chrome,Safari4+ */
- background: -webkit-linear-gradient(top,#cccccc 100%); /* Chrome10+,Safari5.1+ */
- background: -o-linear-gradient(top,#cccccc 100%); /* Opera11.10+ */
- background: -ms-linear-gradient(top,#cccccc 100%); /* IE10+ */
- }
但如果浏览器是IE8,我希望浏览器看到这个:
- div.content_header_heading {
- }
解决方法
Paul Irish很好地解决了这个问题.它涉及使用条件注释在< html>上放置类.标签:
- <!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
- <!--[if IE 7 ]> <html class="ie7"> <![endif]-->
- <!--[if IE 8 ]> <html class="ie8"> <![endif]-->
- <!--[if IE 9 ]> <html class="ie9"> <![endif]-->
- <!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->
然后你可以使用CSS规则来定位IE版本:
- .ie8 div.content_header_heading {
- }
见http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/.