html – 如何为IE设置特殊的CSS?

前端之家收集整理的这篇文章主要介绍了html – 如何为IE设置特殊的CSS?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想为ie8使用一些不同的CSS,但只保留一个CSS文件.谁能告诉我这个最好的“黑客”是什么?是的,我知道黑客不好,但我想保留一个CSS文件,至少目前.

例如,在非IE8浏览器中,我希望浏览器看到这个:

  1. div.content_header_heading {
  2. background: -moz-linear-gradient(top,#cccccc 0%,#eeeeee 35%,#eeeeee 65%,#cccccc 100%); /* FF3.6+ */
  3. 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+ */
  4. background: -webkit-linear-gradient(top,#cccccc 100%); /* Chrome10+,Safari5.1+ */
  5. background: -o-linear-gradient(top,#cccccc 100%); /* Opera11.10+ */
  6. background: -ms-linear-gradient(top,#cccccc 100%); /* IE10+ */
  7. }

但如果浏览器是IE8,我希望浏览器看到这个:

  1. div.content_header_heading {
  2. }

解决方法

Paul Irish很好地解决了这个问题.它涉及使用条件注释在< html>上放置类.标签
  1. <!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
  2. <!--[if IE 7 ]> <html class="ie7"> <![endif]-->
  3. <!--[if IE 8 ]> <html class="ie8"> <![endif]-->
  4. <!--[if IE 9 ]> <html class="ie9"> <![endif]-->
  5. <!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->

然后你可以使用CSS规则来定位IE版本:

  1. .ie8 div.content_header_heading {
  2. }

http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/.

猜你在找的HTML相关文章