Hi there,
I'm trying to use the :first-child and nth-child selectors but I'm running into the same problem.
Can someone please explain to me why this works,
but this doesn't,Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css"> #lastyear .polaroid:first-child span{ background:red; } </style> </head> <body> <div id="container"> <div id="lastyear"> <div class="polaroid"> <span>First model</span> </div> </div> </div> </body> </html>
Note, the addition of the child span of #lastyear in the second example.Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css"> #lastyear .polaroid:first-child span{ background:red; } </style> </head> <body> <div id="container"> <div id="lastyear"> <span>foo</span> <div class="polaroid"> <span>First model</span> </div> </div> </div> </body> </html>
Any help would be much appreciated![]()





Bookmarks