![]() |
adjacent selectors should allow for different elements
I just started implementing child selectors and adjacent siblings selectors into my CSS - previous to now I had used alternate classes or direct styles added to certain elements to get the effects I wanted, but I figured why not take advantage of what was available.
The problem I'm having is that it seems like adjacent sibling selectors (+) don't work with the body element. Anybody know why? Code:
body + div {Code:
span + div {The adjacent selector is supposed to work on different elements but it seems so far that it only supports similar simple elements. p + p, h1 +h2, etc. No body + anything, or span + div... -m |
Shouldnt you use a comma?
|
Nope, that's if you want to style multiple elements.
Code:
/* style all the same */ |
An adjacent sibling is an element that follows right after another, as long as they both have the same parent.
Your problem is that the <div> is in the body, so they don't have the same parents. What you're looking for is the first-child pseudo-class.body > div:first-child { } will select only the first <div> (in the body). |
Yeah I just hardwired the fix into the stylesheet, since :first-child isn't trustworthy. Thank you though.
-m |
True that current browsers (IE) don't support it.
Though, you could use jquery for it to work cross browser. You should check out Selectors/firstChild - jQuery JavaScript Library for it. |
| All times are GMT. The time now is 04:07 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0