2012-06-16 105 views
0

我需要瀏覽器爲客戶端瀏覽器下載相應的腳本。 我需要某種可以工作的switch語句?CSS文件選擇

我有;

  • (common.css)所有瀏覽器腳本需要這個文件
  • (ie6.css)IE 6腳本
  • (ie7.css)IE 7腳本
  • (ie8.css)IE 8腳本
  • (ie9.css)IE 9腳本
  • (other.css)Mozilla的火狐+ + Safari瀏覽器使用相同的適用於所有版本

我有(但千萬esnt工作)

<link rel="stylesheet" href="common.css" type="text/css" /> 

<!--[if IE 6 ]> 
     <link rel="stylesheet" href="ie6.css" type="text/css" /> 
<!--[elseif IE 7 ]> 
     <link rel="stylesheet" href="ie7.css" type="text/css" /> 
<!--[elseif IE 8 ]> 
     <link rel="stylesheet" href="ie8.css" type="text/css" /> 
<!--[elseif IE 9 ]> 
     <link rel="stylesheet" href="ie9.css" type="text/css" /> 
<!--[else]> 
     <link rel="stylesheet" href="other.css" type="text/css" /> 
<![endif]--> 

問:伊夫砍死上面的代碼從另一個文件,但不能得到它的工作? 如果我錯了,是否有更好的switch語句可以使用?

回答

3

我相當肯定,你必須單獨做每個條件,而不是在一個switch語句

<link rel="stylesheet" href="common.css" type="text/css" /> 
    <!--[if IE 6 ]> 
     <link rel="stylesheet" href="ie6.css" type="text/css" /> 
    <![endif]--> 
    <!--[if IE 7 ]> 
     <link rel="stylesheet" href="ie7.css" type="text/css" /> 
    <![endif]--> 
    <!--[if IE 8 ]> 
     <link rel="stylesheet" href="ie8.css" type="text/css" /> 
    <![endif]--> 
    <!--[if IE 9 ]> 
     <link rel="stylesheet" href="ie9.css" type="text/css" /> 
    <![endif]--> 

如果不是IE

<!--[if !IE]> --> 
     <link rel="stylesheet" href="other.css" type="text/css" /> 
    <!-- <![endif]--> 
+0

確定這就是我怎麼樣開始但我需要other.css文件也是有條件的,那麼我如何在if語句中添加它。我的理解是HTML如果是IE的東西? – IEnumerable

+0

你需要另一個文件是基於瀏覽器不是iE的條件嗎? –

+0

是的,所以如果IE其他else.css – IEnumerable

1
<link rel="stylesheet" href="common.css" type="text/css" /> 
<!--[if IE 6 ]> 
    <link rel="stylesheet" href="ie6.css" type="text/css" /> 
    <![endif]--> 
<!--[if IE 7 ]> 
    <link rel="stylesheet" href="ie7.css" type="text/css" /> 
    <![endif]--> 
<!--[if IE 8 ]> 
    <link rel="stylesheet" href="ie8.css" type="text/css" /> 
    <![endif]--> 
    <!--[if IE 9 ]> 
    <link rel="stylesheet" href="ie9.css" type="text/css" /> 
    <![endif]--> 
<!--[if !IE]> --> 
    <link rel="stylesheet" href="other.css" type="text/css" /> 
<!-- <![endif]--> 
+0

謝謝穆薩,我必須首先給予RPM的觀點。 – IEnumerable