Will targeting IE8 with conditional comments work?
Asked Answered
A

7

18

When IE8 is released, will the following code work to add a conditional stylesheet?

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

I've read conflicting reports as to whether this works with the beta. I'm hoping someone can share their experience. Thanks.

Aquilar answered 3/10, 2008 at 16:13 Comment(3)
Wonderful. Yet another non-standard extension from Microsoft.Abbotsun
This one is very old and incredibly useful because it allows non-hack CSS switches to serve different style sheets for MSIE.Cummine
This question should have been closed a long time ago.Forethought
C
14

It worked for me – both in quirks mode and in standards compliance mode. However, it does not work when switching to IE8 compatibility mode.

Cummine answered 3/10, 2008 at 16:18 Comment(2)
Did you mean IE7 compatibility mode?Aquilar
No: Beta 2 has a browser mode and a document mode. Document mode allows for IE 7 compatibility (as well as strict mode and quirks mode). Browser mode has the options “IE 7”, “IE 8” and “IE 8 compatibility mode”. That's what I meant.Cummine
M
22

One thing to note:

It does work, BUT if you are loading the page/site local network (e.g. Intranet) it will load in IE7 mode by default! (update - localhost[*] is a special case, that does render in standards mode)

This goes against MSFT's original statement of going STANDARDS by default.

e.g.

http://127.0.0.1/mysite/mypage.php  <-- IE8 by default (updated!)
http://localhost/mysite/mypage.php  <-- IE8 by default (updated!)
http://machinename/mysite/mypage.php  <-- IE7 by default
http://192.168.100.x/mysite/mypage.php  <-- IE7 by default
http://google.com/  <-- IE8 by default

[*] - Scott Dickens [MSFT] noted in a comment here on the IE Blog that localhost was a special scenario in the Intranet (often used to develop Internet sites) thus would render in Standards mode by default.

To test what mode a page in IE8 is really rendering in, you can use check the developer tools or use this bookmarklet code (only works in IE8):

javascript:
var vMode=document.documentMode;
var rMode='IE5 Quirks Mode';
if(vMode==8){
  rMode='IE8 Standards Mode';
} else if(vMode==7){
  rMode='IE7 Strict Mode';
}
alert('Rendering in: '+rMode);
Marlie answered 3/10, 2008 at 18:5 Comment(5)
I think that depends on the doctype (not sure though, haven't tested): The way I understand Microsoft, IE 8 strict mode is triggered as soon as any valid HTML doctype is specified.Cummine
No, incorrect. IE8 on the local network will render in either IE5 (quirks mode) or IE7's (standards mode) if you have a doctype specified. In order to see a local site rendered in TRUE IE8 STANDARDS mode you Must explicitly tell IE that you want it (e.g. the user must choose this)Marlie
Ok interesting - how do you know this? Can you provide some proof? When I go into the developer tools in IE8 it reports it is running IE8 modes for both rendering and browser mode when loading local pages (e.g. localhost/somepage.html)Appreciate
@Whyamistilltyping - the IE Blog (blogs.msdn.com/ie) posts info on IE progress. For IE8 Beta 2 (blogs.msdn.com/ie/archive/2008/08/27/…) they quote: "In the default state, all sites on the public internet display in Internet Explorer 8 Standards mode (Compatibility View off) and all intranet websites display in Internet Explorer 7 Standards mode (Compatibility View on)." - they did change this behavior later on (thus I'm now updating my answer) that pages loaded from the local machine are an exception and render in standards mode by default.Marlie
...the change occurred in IE8 RC1 for the record. Read the full comments for full details on the cluster... EricLaw [MSFT] "clarified" 5 days later in the comments: blogs.msdn.com/ie/archive/2008/12/03/…Marlie
C
14

It worked for me – both in quirks mode and in standards compliance mode. However, it does not work when switching to IE8 compatibility mode.

Cummine answered 3/10, 2008 at 16:18 Comment(2)
Did you mean IE7 compatibility mode?Aquilar
No: Beta 2 has a browser mode and a document mode. Document mode allows for IE 7 compatibility (as well as strict mode and quirks mode). Browser mode has the options “IE 7”, “IE 8” and “IE 8 compatibility mode”. That's what I meant.Cummine
O
3

Tools/Compatability view settings

uncheck them all

Obsession answered 20/3, 2009 at 15:5 Comment(0)
U
0

Thank you for your help. I've discovered the solution, apparently the problem was having each style sheet use its own title attribute. Once I took the title off all but the main style sheet, no prob.

This is a weird issue unique to IE8 - and although I've been told its supposed to work that way, something to do with "Stylesheet Preference" - it only serves to create problems since the solution requires you remove the title which could be helpful when scripting, etc - when you need to call the style sheet.

In any case, not sure if this is a bug, or its supposed to be that way, but I hope Microsoft investigates further.

Thanks

Unite answered 7/8, 2009 at 19:29 Comment(1)
I think you shouldn't add identical titles to different linked stylesheets. AFAIR that didn't work well in Konqueror either (years ago).Flavin
F
0

Why even bother writing a separate stylesheet for IE8?

If you've already debugged for IE7, you can force IE8 into compatibility mode, and thus display your code as though IE8 were IE7.

All you gotta do is put this RIGHT BELOW the opening head tag. Anywhere else and it won't work.

And then that's a half hour or so less work on average per project, no intense debugging for IE8 needed!

Even Msn.com does this - kind of ironic, eh?

Wrote a blog post about it recently: http://blog.sankhomallik.com/2009/11/16/stop-wasting-time-debugging-on-ie8-when-you-dont-have-to-or-get-ie8-to-behave-like-ie7/

Fractional answered 16/11, 2009 at 21:52 Comment(1)
What happens when IE9 comes along?Jacintajacinth
R
0

IE8 renders pretty nice compared to IE7, I have stylesheets for IE6, IE7 and IE8; at first i thought conditional comments were not working for IE8 after a bit of experimentation i found some rules were not beeing applied by IE8 just because i needed to put the ancestor or parent class first, e.g. i had a class like

.niceclass {some:properties;more:properties;}

it worked only if i changed it for something like:

.parentclass .niceclass {some:properties;more:properties;} or

#parentselector .niceclass {some:properties;more:properties;}

btw in my IE8-only css i have only one overriding rule, the rest is rendered almost like firefox, though thats not making me leave FF anyway!.

Ring answered 21/11, 2009 at 23:34 Comment(0)
D
0

For my part I wanted to use rounded borders using css. IE8 on Vista does not support such. And since the graphics were so that the rounded borders would show a nice rounded shadow as well, the page looked terrible in IE8.

I tried using conditional comments, but to no avail, IE8 would not evaluate the if IE expression and thus would not include the external stylesheet.

Then I had a look at putting it into quirks / compatiblity mode, however, this still did not work as the CSS hacks I had used did no longer work for the IE8.

Last but least I found a working CSS hack that will render the page correctly when in compatibility mode.

* + html #test[id] { color:lime } 

Now, I do not know if this works for IE7 or below, so you would have at least three different hacks for each IE release you want to support, e.e.

* + html #test,
    html+body #test,
    * html body #test
    { color:lime }

I wonder what the next regression of the Internet Exploiter will behold for us.

Danutadanya answered 28/12, 2009 at 9:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.