html - CSS 文件选择

标签 html css

我需要浏览器为客户端浏览器下载合适的脚本。 我需要某种可行的 switch 语句吗?

我有;

  • (common.css) 所有浏览器脚本都需要这个文件
  • (ie6.css) IE 6 脚本
  • (ie7.css) IE 7 脚本
  • (ie8.css) IE 8 脚本
  • (ie9.css) IE 9 脚本
  • (other.css) Mozilla + Firefox + Safari 对所有版本使用相同的样式

我有(但没用)

    <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 语句类型?

最佳答案

我相当确定您必须分别执行每个条件,而不是在 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]-->

关于html - CSS 文件选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11060528/

相关文章:

html - 行高影响背景颜色

javascript - 完成一个步骤后在结帐处打勾

javascript - 从日期选择器中选择正确的日期并限制用户输入错误的日期

html - 覆盖 RefineryCMS 中的布局

html - CSS布局不在同一个位置

css - 如何在价格表中垂直对齐

html - 如何在 HTML/CSS 中设计双引号?

javascript - 为什么每个按钮只能工作一次?

CSS:如果垂直空间可用,则为 "float:bottom"。 "float:left"否则

html - 有没有办法设置元素父级的 CSS?