IE CSS对齐问题

我有以下用 PHP“黑客入侵”的CSS,因为它在IE7中没有正确对齐.有没有更好的方法来做到这一点,而不诉诸PHP?

#Menu
    {
        width: 100%;
        height: 32px;
        padding-top: <?php if(preg_match('/msie/i',$_SERVER['HTTP_USER_AGENT'])){echo '22px';}else{echo '40px';}?>;
        padding-left: 13px;
    }

我想避免使用条件注释并且必须维护多个css文件.

解决方法

哇.是的,不要那样做.你会希望看看使用“条件评论”来包含你想要的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进行大量调整,您可以提前计划并使用“body class”技巧.它在标记中看起来有点丑陋,但它是一种经过验证的技术,有时候会有很多样式表和样式标签.

这里是:

<!--[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常用的排序方式权重分配 排序方式: 1、按类型&#160;...
原文:https://www.cnblogs.com/wenruo/p/9732704.html 先上...
css属性:word-wrap:break-word; 与 word-break:break-all 的...
https://destiny001.gitee.io/color/
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML...
css之background的cover和contain的缩放背景图 对于这两个属...