简体   繁体   English

条件注释不适用于<link>

[英]Conditional comment not working for a <link>

I have aa conditional comment in my page to fix a double padding-top problem with IE7. 我的页面中有一个条件注释,可解决IE7的双重填充问题。

I am trying to add "padding-top:5px;" 我正在尝试添加“ padding-top:5px;” to a DIV only in IE7. 到仅在IE7中的DIV。 The rest of the browsers (including IE6 and IE8) use "padding-top:10px;" 其余的浏览器(包括IE6和IE8)都使用“ padding-top:10px;”。 contained in stylesheet.css. 包含在stylesheet.css中。

stylesheet.css contains stylesheet.css包含

.clImageSamplerText {padding-top:10px;}

stylesheet_ie7.css contains stylesheet_ie7.css包含

.clImageSamplerText {padding-top:5px;}

If I use 如果我用

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

my code works no problem. 我的代码没问题。

If I use 如果我用

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

it does not work. 这是行不通的。

Anyone have any ideas? 有人有想法么?

Just a shot in the dark -- if you are using an XHTML doctype, you might find that closing your <link /> tags will fix the problem. 只是黑暗中的一枪-如果您使用的是XHTML文档类型,则可能会发现关闭<link />标记将解决此问题。

So try: 因此,请尝试:

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

I have included link elements in conditional comments without any problems before, so I don't think it matters that you do that instead of writing it out in a style element. 我之前没有任何问题地将link元素包含在条件注释中,因此我认为不必这样做而不是将其写在style元素中并不重要。 My best guess is that the document is not finding stylesheet_ie7.css . 我最好的猜测是该文档没有找到stylesheet_ie7.css Are you sure it got uploaded to the right place? 您确定将其上传到正确的位置吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM