The two CSS Selector bugs in IE6
Internet Explorer 6's CSS selector support is a far cry from every other A-Grade browser. It doesn't handle attribute tags, adjacent or child selectors, or the :first-child psuedo-selector. And yes, it sucks. We deal with it.
But beyond selectors not being implemented, there are two BUGS when it comes to selectors in IE6:
- The multiple class bug
- When you define rules like:
p.disclosure.warning { text-align: center; color: red; }
Most browsers will apply this to any P tags with both the class disclosure and warning. IE6, however, will only apply this to P tags with the last class mentioned; in this case, P tags with the class warning. so IE6 pretends like you wrote:
p.warning { text-align: center; color: red; } /* no .disclosure */
Workarounds are typically not hard, but staying aware of this fact will save you time debugging.
- The ID-class bug
- When you define a block like:
#tooltip.red { background: white; color: red; } #tooltip.yellow { background: black; color: red; }
IE will ignore the the second rule. So even if you have a
<div id="tooltip" class="yellow">I'm on a black background in yellow text!</div>
, IE will not apply the CSS styles you had defined for it. If you have laid our rules for the same ID but different classes, it will ignore all CSS rules defined after the first one. (Your red tooltip will be fine).
Solutions:
- Don't let the #id.class combo be the last selector: Multiple selectors of this type
#tooltip.yellow divwill be fine. - Move the class to a parent container:
div.yellow #tooltipwill not mess up anything. - Make your classes be superspecific and dont use an ID in your selector:
div.yellowtooltip. You'll have to repeat yourself with duplicate CSS definitions, but you can thank IE6 for making your day miserable, yet again. :)
- Don't let the #id.class combo be the last selector: Multiple selectors of this type
Your first solution worked like a charm. Thanks for the help!
How much market share does IE6 have to lose before we can forget about it? For me, once it hits 10%, I completely don't care.
I got bit by both of these over the weekend, and it is good to see what was really the problem. Thanks for posting.
Oh, and: I hate IE
I've switched the id with the class, so that now instead of
, I have
Same class, multiple id's. Seems to work :)
I meant
hi @Mike
and
but it doesn't work for ie6
@Eric Mill http://www.ie6countdown.com/
http://www.theie7countdown.com/
http://www.theie8countdown.com/
and lastly http://www.theie9countdown.com/
first one is an official MS one.