Domanda

I am trying to make a website look better in IE, so i decided to use conditional comments. 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.

È stato utile?

Soluzione

Here is the correct format of the comment:

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

here is a NOT IE comment:

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

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

edit: just noticed that their 'not' example is wrong. i have corrected it.

Altri suggerimenti

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

reference link 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.

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

HTML conditional comments were disabled in IE10. CSS conditional comments can be used to target styling in IE10+.
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. 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. 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.

Only browsers running ES6 and supporting modules will run scripts included with type="module".

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top