Asked by Andrew a freelance designer from Chicago
How come when i have the “if IE” link to the css, it doesn’t change at all?
It’s linked correctly and the “if IE” is correct, but the css just isn’t showing.
I think cause the link to the regular css is over-riding the “if IE” one. Why won’t it work?
Right off the top of my head.
If you are using multiple versions of Internet Explorer on the same machine you will experience issues with version targeting like “If IE”.So if you are using a Standalone IE6 or Standalone IE7, refer to the manufacturers of the standalones for workarounds.
Conditional comments and version targeting
Conditional comments only work in Internet Explorer, and are used to target specific versions. They use the HTML Comment structure, and thus are placed in the HTML not the CSS.
Example
<!–[if IE 6]>
<link href=”../ie6.css” rel=”stylesheet” ………. />
<![endif]–>
This makes them perfect for linking to alternate IE only stylesheets, which for example, wouldn’t use 24-bit PNG transparency etc.
Troubleshooting
This script comes off the very handy Quirksmode.org website. It will run through the different versions available to show you what your browser is behaving as.
From: http://www.quirksmode.org/css/condcom.html
<p><!–[if IE]>
According to the conditional comment this is Internet Explorer<br />
<![endif]–>
<!–[if IE 5]>
According to the conditional comment this is Internet Explorer 5<br />
<![endif]–>
<!–[if IE 5.0]>
According to the conditional comment this is Internet Explorer 5.0<br />
<![endif]–>
<!–[if IE 5.5]>
According to the conditional comment this is Internet Explorer 5.5<br />
<![endif]–>
<!–[if IE 6]>
According to the conditional comment this is Internet Explorer 6<br />
<![endif]–>
<!–[if IE 7]>
According to the conditional comment this is Internet Explorer 7<br />
<![endif]–>
<!–[if gte IE 5]>
According to the conditional comment this is Internet Explorer 5 and up<br />
<![endif]–>
<!–[if lt IE 6]>
According to the conditional comment this is Internet Explorer lower than 6<br />
<![endif]–>
<!–[if lte IE 5.5]>
According to the conditional comment this is Internet Explorer lower or equal to 5.5<br />
<![endif]–>
<!–[if gt IE 6]>
According to the conditional comment this is Internet Explorer greater than 6<br />
<![endif]–>
</p>
Its always preferable to avoid using conditional targeting and try to work within the css to support the major browsers, but unfortunately the real world sometimes calls for harsher measures.
For the adventurous, try the conditional comments and mix them with progressive enhancement.
See more posts under: Tips & Tweaks
OR see posts tagged with: compatability | css | internet explorer
You may also like:
OR follow on Twitter
Twitter.com/DeDestruct
Comments
Good article. One thing though: I think you mean 32-bit PNG. 24-bit PNG’s don’t have transparency.
I believe that 24bit PNGs have variable transparency which is alpha transparency
i could be wrong, going to do some research on all the differences between
8/24/32 bit PNGs
Thanks! But one more thing, when I have the other CSS (the IE css), do i have to have the whole entire CSS in it? And not just the parts that fix the stuff in IE? Otherwise thank you soo much! You guys are a great help.
Just the IE parts
What was the conditional statement for firefox??? Do you write:
[if lte Firefox] or [if lte Mozilla]???
there is no conditional stament for firefox sadly
I’m sure that later, they will have it, and it would be [if Mozilla] or maybe [if M] or [if Mz] or [if Ml] or something.
I am not a big fan of these kind of conditional statements. I feel the website is better of to use markup that works for all browsers in all situations. If you need help I have a great CSS template cheats resource http://www.zachgraeve.com/css-cheats/ that can eliminate a lot of guess work when creating a CSS driven layout.
zacheos’s last blog post… Shiny Orb Button / Icon - Powered by CommentLuv
Nice post but you have made a glaring mistake by coding your conditional comments incorrectly.
Rather than coding
< ! - [if IE] > css rule < ! [end if] - >you should have an extra dash at the beginning and at the end or the browser does not see it as a comment.
It should be;
< ! - - [if IE] > css rule < ! [end if] - - >You haver even quoted the quirksmode site, which shows it correctly at http://www.quirksmode.org/css/condcom.html.
Other than that, nice site, keep it up
PS: re-Andrew No.6 comment,
There is no conditional comment for Firefox because it is a good browser that really doesn’t require many hacks. You should be building your site using Firefox to view it (or another equally standards compliant browser - not IE) and then use conditional comments to force extra style rules that are required for IE.
Ray’s last blog post… Slow motion lightning - Powered by CommentLuv
your comment system wont allow for the correct tag insertion
go here and do what this says
http://www.quirksmode.org/css/condcom.html.
Ray’s last blog post… Slow motion lightning - Powered by CommentLuv
Umm… For Zacheos … Creating for all browsers is impossible in a lot of situations. This is due to the differences in IE .. In other words IE is evil and handles css different for each IE version.
If you develop for IE6 and then a separate for IE7 and firefox you should be good to go.
If you just develop for ie6 and not ie7 your css is foreign. Especially if you use transparent 24 png for layouts images logos etc.
deleted because code does not display.
sorry.
Re:
# 3. Andrew says April 9th, 2008 at 8:28 pm
Thanks! But one more thing, when I have the other CSS (the IE css), do i have to have the whole entire CSS in it? And not just the parts that fix the stuff in IE? Otherwise thank you soo much! You guys are a great help.
# Ayush Saran is the author of this post 4. Ayush Saran says April 9th, 2008 at 10:11 pm
Just the IE parts
–I’m a new developer and just created a page using a conditional comment:
Which worked great. However, I tried removing the extraneous style definitions that were not IE6 specific and the page started to blow up pre-IE6.css. I ended up leaving in almost all duplicate style definitions. If someone has some insight that would be great (post comment here or email me).
Thank you!
Sara
# 3. Andrew says April 9th, 2008 at 8:28 pm
Thanks! But one more thing, when I have the other CSS (the IE css), do i have to have the whole entire CSS in it? And not just the parts that fix the stuff in IE? Otherwise thank you soo much! You guys are a great help.
# Ayush Saran is the author of this post 4. Ayush Saran says April 9th, 2008 at 10:11 pm
Just the IE parts
–I’m a new developer and just created a page using a conditional comment:
Which worked great. However, I tried removing the extraneous style definitions that were not IE6 specific and the page started to blow up pre-IE6.css. I ended up leaving in almost all duplicate style definitions. If someone has some insight that would be great (post comment here or email me).
Thank you!
Sara
On the media=”" you should have “screen” for your IE file.
I created a web site which used a table to arrange the page. Then using css in my header, I place some of text in absolute positions.
Firefox read the absolute positions from the absolute left margin. IE and Chrome and Opera and Safari, (all the webkit using engines), read the absolute position from the edge of the table, which is 10% left from the margin. Using conditional IE statements I was able to fix the site for IE. I have tried various conditional statements offered for webkit , which I found on the web, however, none are working. I also tried the conditional statement for gecko given above, and it hasn’t helped yet. (PS, despite what someone said above, I found alot of web sites that claim to have working conditional statements for most browsers).
Just to assure… The script works excellent. And it is not mine. I am developer myself too, and for me it works. And according w3s validated also. Click on my name and see yourself. As i am continually developing, sometimes errors creep up, but as soon as known — have to find out myself… People do not seem to know what feedback is on my site…–, adjust some rule and green again. All browsers. All browsers where you place rules for. Make up your own if you like.
Nice header, by the way.
Oh… and its a script, that means it is done behind the scenes.
@sara Use:
if lte IE 6
Translation: If less than or equal to IE6.
This will target IE6 and lower.
It’s sad we still have to use these hacks. We have such sophisticated technology now a days but yet all browsers cannot be uniform.
Agree totally with Tim… we can send man to the moon but still can’t develop browsers to render websites in the same way.. very very sad
If anyone is still looking - I found this solution:
http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx
(then page down to “Detecting Firefox“)
Trackbacks
Leave a reply