条件注释不适用于<link />

时间:2010-02-23 19:46:29

标签: html internet-explorer-7 conditional comments

我的页面中有条件注释来修复IE7的双填充顶部问题。

我正在尝试添加“padding-top:5px;”仅在IE7中的DIV。其余的浏览器(包括IE6和IE8)使用“padding-top:10px;”包含在stylesheet.css中。

stylesheet.css包含

.clImageSamplerText {padding-top:10px;}

stylesheet_ie7.css包含

.clImageSamplerText {padding-top:5px;}

如果我使用

<link href="stylesheet.css" rel="stylesheet" type="text/css">
<!--[if IE 7]>
    <style>.clImageSamplerText {padding-top:5px;}</style>
<![endif]-->

我的代码没问题。

如果我使用

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

它不起作用。

有人有什么想法吗?

2 个答案:

答案 0 :(得分:0)

只是在黑暗中拍摄 - 如果您使用的是XHTML文档类型,您可能会发现关闭<link />标记可以解决问题。

所以试试:

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

答案 1 :(得分:0)

我之前在条件注释中包含了link个元素而没有任何问题,因此我认为您不会在style元素中将其写出来并不重要。我最好的猜测是该文件没有找到stylesheet_ie7.css。你确定它上传到了正确的地方吗?

相关问题