Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

CSS Forum


You are currently viewing our CSS Forum as a guest. Please register to participate.
Login



Reply
first-child vs nth-child(1) cage match
Old 07-19-2011, 12:39 AM first-child vs nth-child(1) cage match
TWD
TWD's Avatar
King Spam Talker

Posts: 1,183
Trades: 0
In case the heading isnt obvious what I am asking is, all else being
considered equal, assume you want to target the first <p> element in a string
of similar <p> elements

You could do it with either:

p:first-child

or

p:nth-child(1)

[remembering that nth-child uses "1" index syntax, not zero index
like an array]

So I am looking for arguments in favor or against one or the other.
Pros or cons.
E.g. which is best for most robust browser compatibility.
Or if you like, efficiency of parsing for the browser.

Which is best practice in your view?
__________________
RATE-MY-WEBSITE.com "Free website reviews by real web professionals"
Please login or register to view this content. Registration is FREE
TWD is online now
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-19-2011, 04:06 AM Re: first-child vs nth-child(1) cage match
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
It seems logical to me that the implementation of first-child would just be an alias for nth-child(1). And with that logic, all browsers that supports first-child also supports nth-child. Don't take my word on that though, I'm really only guessing here.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 07-19-2011, 04:59 AM Re: first-child vs nth-child(1) cage match
TWD
TWD's Avatar
King Spam Talker

Posts: 1,183
Trades: 0
Actually, I just found out that while first-child seems well supported,
nth-child is NOT supported in Internet Explorer (even up to IE8 which is
surprising. No idea about IE9).

Also Firefox below vers 3.5 doesnt support it.

First-child is supported by all browsers except IE6
(but as far as I'm concerned, stick a fork in IE6 cause its done.
I dont support that browser any more).

http://kimblim.dk/css-tests/selectors/

Seems like we have a winner.
__________________
RATE-MY-WEBSITE.com "Free website reviews by real web professionals"
Please login or register to view this content. Registration is FREE

Last edited by TWD; 07-19-2011 at 05:00 AM..
TWD is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to first-child vs nth-child(1) cage match
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.49201 seconds with 12 queries