views:

246

answers:

7

The main culprit behind this question is of course IE6, (almost) everybody agrees that a website should support IE6 since it is used by more than 15% of the visitors (for Yahoo it is still an A-Graded browser).

IE6 doesn't support CSS 2.1, so can we use CSS 2.1 selectors in our stylesheets? Let me give an example:

<body>
    <div class="header">
    </div>
    <div class="content">
        <h1>Title</h1>
        <p>First paragraph</p>
        <p>Second paragraph</p>
    </div>
    <div class="footer">
    </div>
</body>

My css could look like this:

body > div {width: 760px;} /*header content and footer = 760px wide*/
h1 + p { margin-top: 5px;} /* the first paragraph after the h1 tag should have a smaller margin

But IE6 won't understand this, so anyway to be browser compatible I should write it like this:

.header, .content, .footer  { width:760px; }

And probably I have to give the first paragraph some class name and define it like that in my css. I could make a IE6 stylesheet specific that defines those rules, but that seems so double up (and still doesn't help in the case of the first paragraph needing a class name)...

+1  A: 

If you're serious about supporting IE6 100% then you should avoid using CSS that wont work with it. One of the reasons for using those fancy selectors is to make your life easier, but it's not going to make your life easier if you have to rewrite them anyway for IE6. Finally, fancy selectors like that are slow in Firefox, so maybe just avoid them all together.

apphacker
Thanks for pointing to that document... The CSS world could be so much cleaner if we could use all its goodness.
Gidon
A: 
  • Javascript like JQuery.
  • CSS Hack. But I don't suggest it. Because it isn't W3C standard.
  • CSS Classname. By using CSS Classname replaces CSS Selector.
Soul_Master
A: 

Your browser audience will dictate what you support as you've already stated, even a 'techy' website like w3schools still reports the IE6 market share at 17% for march.

That said, if you're going to support it, obviously you need alternatives.

I read another intersting thread about targetting just IE8 yesterday on stackoverflow, and I suspect supporting each browser will be easier if you can target them. I'm in a .net environment and use the approach that someone posted about half way down that thread so that my CSS selectors can very readily become:

body > div {width: 760px;}
.IE6 div.header, .IE6 div.content, .IE6 div.footer { width: 760px; }

Obviously you would find your own way of targetting browsers, but the CSS will equate to something similar.

Terry_Brown
and in answer to your follow up question, I'd think the client and target market dictates really. That ugly redundant code you mention is something web devs have lamented over for years (IE6 should have been taken out long ago and shot), but in delivery of client sites, if the market share of IE6 dictates that it's necessary, then we must do it unfortunately.
Terry_Brown
+1  A: 

If you approach your site design from a progressive enhancement perspective then you should be fine, as more modern browsers will just get a better experience than those using ie6. If you are just looking to cut corners or save time developing, then you have to make a choice if ie6 users are important for your site or not.

Ronny Vindenes
This. It's what we do, though in practice I have far more problems with javascript and the deficiencies in the IE<8 DOM than in CSS incompatibilities.
Pete Jordan
A: 

It's not to the developer but to the site owner to decide whether to ignore IE6. You should give the site owner the stats for that specific site and then the decision should be made.

If you, or the owner, decide to NOT sacrifice the IE6 folks then it makes no sense whatsoever to use those fancy selectors. There is big downside and no upside as of yet.

allesklar
A: 

For every IE6 user on mine site I got big red alert saying, their browser is ancient, and they should download a real browser, like Firefox ;] That's the solution. If webmasters won't say it to users, who will?

Thinker
+1  A: 

I think the concept of "supporting" IE6 is the wrong idea, if we say no to that are we just not going to allow IE6 users access to our site and content? Of course not. So the question really is, how much time do you want to spend making the experience of your site the same for IE6 as other browsers.

My own standpoint is that I "support" IE6, in that a user of IE6 will be able to access all a site's content and all it's features, but they might not get the same visual or interaction experience as a Firefox 3 user.

So to answer your question, yes we can use CSS 2.1 and 3.0 selectors to achieve certain affects, as long as the content is still there for IE6 and with an acceptable visual appearance. What's acceptable will depend on the project (and likely the client!).

Your example was a good showcase of this:

p { margin-top: 10px; }
h1 + p { margin-top: 5px;} /* the first paragraph after the h1 tag should have a smaller margin

Here IE6 will still get the paragraph content, and there will still be all important white-space between them, they just won't get the reduced spacing on the first one. That's a fair compromise IMO for the reduced clutter in your HTML.

Another good example would be rounded corners. You can use -moz-border-radius and -webkit-border-radius to get rounded corners in Firefox and Safari, enhancing the visual experience of your site, but IE users still get the content albeit with plain old square corners (and then there are plenty of JavaScript solutions out there to achieve this for people with JavaScript enabled).

This would all come under the heading Progressive Enhancement

roryf
I realise rounded corners have nothing to do with CSS selectors, but I think it's a good example of the concept
roryf