哇。是的,不要这样做。你会想要使用“条件注释”来包含你想要的CSS。您的第一位评论者bendewey已经向您展示了如何轻松定位IE7。还有其他类型的条件注释,它们将允许您定位其他版本的IE。
在这里,他们是:
<!--[if IE]>
According to the conditional comment this is Internet Explorer
<![endif]-->
<!--[if IE 5]>
According to the conditional comment this is Internet Explorer 5
<![endif]-->
<!--[if IE 5.0]>
According to the conditional comment this is Internet Explorer 5.0
<![endif]-->
<!--[if IE 5.5]>
According to the conditional comment this is Internet Explorer 5.5
<![endif]-->
<!--[if IE 6]>
According to the conditional comment this is Internet Explorer 6
<![endif]-->
<!--[if IE 7]>
According to the conditional comment this is Internet Explorer 7
<![endif]-->
<!--[if gte IE 5]>
According to the conditional comment this is Internet Explorer 5 and up
<![endif]-->
<!--[if lt IE 6]>
According to the conditional comment this is Internet Explorer lower than 6
<![endif]-->
<!--[if lte IE 5.5]>
According to the conditional comment this is Internet Explorer lower or equal to 5.5
<![endif]-->
<!--[if gt IE 6]>
According to the conditional comment this is Internet Explorer greater than 6
<![endif]-->
如果你打算做了很多不同版本的IE浏览器的调整,可能会提前计划,用“身体课”的把戏。它看起来有点丑陋,但它是一种成熟的技术,有时它会打败很多样式表和样式标签。
这就是:
<!--[if !IE]>--><body><!--<![endif]-->
<!--[if IE 6]><body class="ie6"><![endif]-->
<!--[if IE 7]><body class="ie7"><![endif]-->
<!--[if IE 8]><body class="ie8"><![endif]-->
而在你的样式表,你只是会附上一个类来选择重置任何你想要的风格。像这样:
#some_div {
margin-top:30px;
}
.ie6 #some_div {
margin-top:40px;
}
.ie7 #some_div {
margin-top:50px;
}
希望这是有道理的。无论哪种方式,它都是您希望使用的条件注释,而不是PHP。
你想避免条件或多个CSS文件,但混合PHP到你的CSS?这有点落后。 如果将CSS移动到外部文件,该怎么办?在这种情况下你不能使用php。 – patricksweeney 2009-02-10 04:57:23
该CSS位于名为css.css.php的外部文件中,并且该问题表明他不想使用PHP ...所以我看不出您的评论如何有效。 – UnkwnTech 2009-02-10 04:59:44