简体   繁体   English

IE 样式表/条件注释不起作用

[英]IE Stylsheets/ Conditional comments Not working

I am trying to make a website look better in IE, so i decided to use conditional comments.我试图让一个网站在 IE 中看起来更好,所以我决定使用条件注释。 So I used this conditional comment to link to the stylesheet.所以我使用这个条件注释链接到样式表。

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

That doesn't work, and it will either use the default stylesheet or it will display a blank page.这不起作用,它将使用默认样式表或显示空白页面。 So then i read somewhere that the comments were like this.然后我在某处读到评论是这样的。

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

So i tried that and it did the exact same thing as the other one but the --> shows up on the page.所以我试过了,它和另一个做了完全相同的事情,但-->显示在页面上。 I am still somewhat new to html, and any help would be nice.我对 html 还是有点陌生​​,任何帮助都会很好。

Here is the correct format of the comment:以下是评论的正确格式:

<!--[if IE ]>
Special instructions for IE here
<![endif]-->

here is a NOT IE comment:这是一个 NOT IE 评论:

<!--[if !IE ]>
According to the conditional comment this is not IE
<![endif]-->

source: http://www.quirksmode.org/css/condcom.html来源: http : //www.quirksmode.org/css/condcom.html

edit: just noticed that their 'not' example is wrong.编辑:刚刚注意到他们的“不是”示例是错误的。 i have corrected it.我已经改正了。

You should use like this : Syntax :你应该这样使用:语法:

<!--[if IE 8]> = IE8
<!--[if lt IE 8]> = IE7 or below
<!--[if gte IE 8]> = greater than or equal to IE8


<!--[if IE 8]>
<style type="text/css">
    /* css for IE 8 */
</style>
<![endif]-->

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

reference link 1 参考链接 1

reference link 2 参考链接2

Also its always good to declare what versions of IE you want to pull up the conditional sheet, for example if you want IE 9 and lower it would be as stated below.此外,声明您想要拉出条件表的 IE 版本总是好的,例如,如果您想要 IE 9 和更低版本,则如下所述。

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

HTML conditional comments were disabled in IE10. HTML 条件注释在 IE10 中被禁用。 CSS conditional comments can be used to target styling in IE10+. CSS 条件注释可用于在 IE10+ 中定位样式。
https://www.mediacurrent.com/blog/pro-tip-how-write-conditional-css-ie10-and-11/ https://www.mediacurrent.com/blog/pro-tip-how-write-conditional-css-ie10-and-11/

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
// IE10+ CSS here
}

When faced with this problem, we went with the <script type="module"> solution.面对这个问题时,我们采用了<script type="module">解决方案。 More details here .更多细节在这里

We also wanted to access global variables we set using the ES6 code from other ES5 scripts to determine if we wanted to do something different.我们还想访问我们使用来自其他 ES5 脚本的 ES6 代码设置的全局变量,以确定我们是否想做一些不同的事情。 Obviously an export isn't going to work in this case, but you can assign variables to window.<something> and then access them like you would any other variable.显然,在这种情况下导出将不起作用,但您可以将变量分配给window.<something>然后像访问任何其他变量一样访问它们。

Only browsers running ES6 and supporting modules will run scripts included with type="module" .只有运行 ES6 和支持模块的浏览器才会运行包含在type="module"脚本。

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

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