Synook Posted August 21, 2007 Share Posted August 21, 2007 Hello all,I'm sure there was an old topic about this but I can't seem to find it. So, how would I create a CSS definition that only selects the direct children of a certain element. So, say I wanted to have a style for all tables in a document, but not tables within those tables. Instead I just want to have a style for tables that are direct children of the <body> element, i.e. for body table but not for body table table. Link to comment Share on other sites More sharing options...
Kingy Posted August 21, 2007 Share Posted August 21, 2007 By any chance are you thinking of :first-child and :last-child? Link to comment Share on other sites More sharing options...
boen_robot Posted August 21, 2007 Share Posted August 21, 2007 :first-child selects the first child of the childs of an element. For example: <body> <div id="first"> <div id="firstFirst"> </div> <div id="firstSecond"> </div> </div> <div id="second"> </div></body> with body div:first-child {background-color:#000;color:#FFF;} will only match #first and #firstFirst.You can get all of the first div children (#first and #second, without #firstFirst and #firstSecond) with body > div The later is not supported in IE6 (I think) and :first-child. I'm not sure, but I think in IE7, it behaves like the later (haven't tested IE6, and I wasn't testing exactly that on IE7 either). Link to comment Share on other sites More sharing options...
Synook Posted August 21, 2007 Author Share Posted August 21, 2007 Ah right. Thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted August 21, 2007 Share Posted August 21, 2007 Check the list of selectors:http://www.w3.org/TR/REC-CSS2/selector.htmlE > F will match an element F that is a child of an element E. So this:div > awill match this:<div><a>but not this:<div><p><a>Also, this:E + F will match any element F that is preceded by an element E. So this:div + spanwill match this span element:<div></div><span></span>because it is preceeded by a div. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.