2014-10-21 62 views
1

我使用的条件语句这里添加ie浏览器CSS样式即有条件的HTML语句

<!DOCTYPE html> 
    <!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]--> 
    <!--[if IE 7]> <html class="lt-ie9 lt-ie8"> <![endif]--> 
    <!--[if IE 8]> <html class="lt-ie9"> <![endif]--> 
    <!--[if gt IE 8]><!--> <html class=""> <!--<![endif]--> 

如果我在模拟器测试这个条件语句似乎并没有工作,HTML标记没有'lt-ie9'级。

如果我的产品,如browserstack条件语句测试似乎工作,我可以看到的文字多数民众赞成在显示与类.LT-IE9

是有条件的html标记是否正确?如果我不相信模拟器

<!DOCTYPE html> 
    <!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]--> 
    <!--[if IE 7]> <html class="lt-ie9 lt-ie8"> <![endif]--> 
    <!--[if IE 8]> <html class="lt-ie9"> <![endif]--> 
    <!--[if gt IE 8]><!--> <html class=""> <!--<![endif]--> 
     <head> 
      <meta charset="UTF-8"> 
      <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 

      <!--jQuery--> 
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> 

      <!--css--> 
      <style type="text/css"> 

      .test{ 
      color: red; 
      display: none; 
      font-size: 2em; 
      } 

      .lt-ie9 .test{ 
      display: block; 
      } 

      </style> 


      <!--[if lt IE 9]> 
       <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
      <![endif]--> 

      <title>Title of the document</title> 
     </head> 

    <body> 

     <div class="test">IE8</div> 

    </body> 

    </html> 

回答

1

不知道有问题的模拟器,我们无法知道。您在调试过程中的最佳做法是将该代码复制到主体中,并用可见的东西替换html标签:

<!--[if lt IE 7]> IE, Less than 7<![endif]--> 
<!--[if IE 7]> IE 7 <![endif]--> 
<!--[if IE 8]> IE 8 <![endif]--> 
<!--[if gt IE 8]><!--> IE 9+ or not-IE <!--<![endif]-->