views:

178

answers:

4
+4  Q: 

CSS first-child

Hello there.

Is it safe to use CSS pseudo class first-child with regards to browser support and the like?

Thanks.

+6  A: 

Depends which browser.

IE6 doesn't support it. See :first-child and :last-child:

Not supported by Explorer 6- on Windows.

Explorer 7, Safari 3.0, iCab only support :first-child.

cletus
Someone should run a test. PPK is usually very good about noting things like that, and W3Schools isn't always accurate.
D_N
Yep, I just ran a test. IE6 doesn't see :first-child. (Testing on Internet Explorer Collection.) This is how I remember it, too.
D_N
Seriously, one of you should edit that W3schools reference--it's not very clear. What's the current IE? And 'to work in IE' means 'to work in the current IE'--not 6. Perty please.
D_N
w3schools is a relic of history that's best left ignored. If you want to know about current functionality go to quirksmode.
cletus
Agreed, and not to be a pain, but can't you revert your answer so it doesn't include the erroneous info?
D_N
@DN sorry didn't even notice that had been added.
cletus
No mention of Firefox?
Mike D.
And no mention of Opera, which does support it: http://reference.sitepoint.com/css/pseudoclass-firstchild
jrista
A: 

According to w3 it's supported by all major browsers (ie, firefox, opera, chrome, safari) with the caveat that for :first-child to work in ie, a < !DOCTYPE> must be declared.

dagoof
**current** IE, but not IE6
Pointy
+1  A: 

You can support CSS2 pseudo-classes in IE5/IE6 by using Dean Edwards IE7 JS library

http://dean.edwards.name/IE7/

It's free, easy to use and highly recommended. Just put the following code in your HEAD:

<!--[if lt IE 7]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta2)/IE7.js"&gt;&lt;/script&gt;
<![endif]-->

Despite the BETA label It's never given me any problems and it solves a whole range of IE6 lameness issues.

SpliFF
+1 for Dean Edwards IE7. I have used that a few times in the past, and, while a little slow, seems to work like a dream.
jrista
A: 

jQuery would be another option to solve this cross browser.

xentek