CONDITION CSS区分IE6到IE7

时间:2021-08-15 11:51:16

i want to declare a style different to ie6 and ie7 , but my condition in css recognized by IE7 as IE6. I use XP and explorer 7. This the code i use :

我想声明一个与ie6和ie7不同的样式,但我在css中的条件被IE7识别为IE6。我使用XP和资源管理器7.这使用的代码:

<!--[if !IE]>

#mainDiv{text-align:-moz-center;}

#skyBanner {top:0px;left:0px; position:fixed;visibility:hidden;}

<![endif]-->     

<!--[if lt IE 7]>

body > #skyBanner {  position: fixed;}

#skyBanner {position:absolute;visibility:hidden;

left: expression( ( 0 + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + 'px' );

top: expression( ( 0 + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px' );

}

<![endif]-->

<!--[if IE 7]>

#skyBanner {position:fixed;visibility:hidden;

}    
<![endif]--> 

what is my mistake?

我的错是什么?

3 个解决方案

#1


You can't use conditional comments in CSS. Only in HTML. So you'd have to put the declarations for the different browsers into different files and conditional-comment several <link>s to them.

您不能在CSS中使用条件注释。仅限HTML。因此,您必须将不同浏览器的声明放入不同的文件中,并对其中的几个 进行条件注释。

So more something along the lines of

所以有更多的东西

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

#2


Your !IE is incorrectly commented, and you are missing style tags. If this is exactly how it exists in your HTML then that is your problem. If this is in a CSS file then you cannot use conditional comments in that location.

您的IE浏览器评论错误,您缺少样式标记。如果这正是HTML中存在的那么,那就是你的问题。如果这是在CSS文件中,那么您不能在该位置使用条件注释。

Corrected:

<!--[if !IE]>-->
<style type="text/css" media="screen">
    #mainDiv {text-align:-moz-center;}
    #skyBanner {top:0px;left:0px; position:fixed;visibility:hidden;}
</style>
<!--<![endif]-->

<!--[if lt IE 7]>
<style type="text/css" media="screen">
    body > #skyBanner {  position: fixed;}
    #skyBanner {position:absolute;visibility:hidden;
    left: expression( ( 0 + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + 'px');
    top: expression( ( 0 + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px' );
    }
</style>
<![endif]-->

<!--[if IE 7]>
<style type="text/css" media="screen">
    #skyBanner {position:fixed;visibility:hidden;}
</style>
<![endif]-->

Again, as it is currently written, NO browser is seeing the !IE code.

再次,正如目前所写,没有浏览器看到!IE代码。

I'm also not sure you've written the other conditionals correctly. You have "body > #skyBanner {position: fixed;}" under the "if lt IE 7" conditional, yet IE6 and lower do not support this CSS selector to my knowledge.

我也不确定你是否正确地编写了其他条件。您在“if lt IE 7”条件下有“body> #skyBanner {position:fixed;}”,但IE6及更低版本不支持我的CSS选择器。

So any number of the issues I've described could be leading to your problems with IE6 and IE7.

因此,我所描述的任何问题都可能导致您对IE6和IE7的问题。

#3


You need to do it a bit different way. Use comments and enclose links to browser specific CSS files. This way it should work:

你需要做一些不同的方式。使用注释并将链接附加到浏览器特定的CSS文件。这样它应该工作:

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

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

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

You can also use <style> tags instead of links, but this is a bad way of doing this.

您也可以使用

#1


You can't use conditional comments in CSS. Only in HTML. So you'd have to put the declarations for the different browsers into different files and conditional-comment several <link>s to them.

您不能在CSS中使用条件注释。仅限HTML。因此,您必须将不同浏览器的声明放入不同的文件中,并对其中的几个 进行条件注释。

So more something along the lines of

所以有更多的东西

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

#2


Your !IE is incorrectly commented, and you are missing style tags. If this is exactly how it exists in your HTML then that is your problem. If this is in a CSS file then you cannot use conditional comments in that location.

您的IE浏览器评论错误,您缺少样式标记。如果这正是HTML中存在的那么,那就是你的问题。如果这是在CSS文件中,那么您不能在该位置使用条件注释。

Corrected:

<!--[if !IE]>-->
<style type="text/css" media="screen">
    #mainDiv {text-align:-moz-center;}
    #skyBanner {top:0px;left:0px; position:fixed;visibility:hidden;}
</style>
<!--<![endif]-->

<!--[if lt IE 7]>
<style type="text/css" media="screen">
    body > #skyBanner {  position: fixed;}
    #skyBanner {position:absolute;visibility:hidden;
    left: expression( ( 0 + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + 'px');
    top: expression( ( 0 + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px' );
    }
</style>
<![endif]-->

<!--[if IE 7]>
<style type="text/css" media="screen">
    #skyBanner {position:fixed;visibility:hidden;}
</style>
<![endif]-->

Again, as it is currently written, NO browser is seeing the !IE code.

再次,正如目前所写,没有浏览器看到!IE代码。

I'm also not sure you've written the other conditionals correctly. You have "body > #skyBanner {position: fixed;}" under the "if lt IE 7" conditional, yet IE6 and lower do not support this CSS selector to my knowledge.

我也不确定你是否正确地编写了其他条件。您在“if lt IE 7”条件下有“body> #skyBanner {position:fixed;}”,但IE6及更低版本不支持我的CSS选择器。

So any number of the issues I've described could be leading to your problems with IE6 and IE7.

因此,我所描述的任何问题都可能导致您对IE6和IE7的问题。

#3


You need to do it a bit different way. Use comments and enclose links to browser specific CSS files. This way it should work:

你需要做一些不同的方式。使用注释并将链接附加到浏览器特定的CSS文件。这样它应该工作:

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

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

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

You can also use <style> tags instead of links, but this is a bad way of doing this.

您也可以使用