2014-10-21 95 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]-->