Possible Duplicate:
CSS Child vs Descendant selectors
So, what's the difference here?
div a {
/* Styles here */
}
and
div > a {
/* Styles here */
}
I really don't understand.
Possible Duplicate:
CSS Child vs Descendant selectors
So, what's the difference here?
div a {
/* Styles here */
}
and
div > a {
/* Styles here */
}
I really don't understand.
space
is the descendant combinator, while >
is the child combinator. Child means direct descendant, descendant means a node somewhere in the subtree of the parent element, no matter how deep.
To put it in plain words:
div a {/*properties*/}
This would select and apply the given style to all the 'a' elements in a 'div'.
div > a {/*properties*/}
This will select only the direct child 'a' tags inside the div.
For instance:
css:
div > a {color: red}
html:
<div>
<a href="#">Link One</a>
<span>
<a href="#">Link Two</a>
<a href="#">Link Three</a>
</span>
<a href="#">Link Four</a>
</div>
Here, red color will only be applied to 'Link one' and 'Link Four'. 'Link Two' & 'Link Three' are not selected since they are nested inside a 'span' element.
Play around with them: http://dabblet.com/gist/3730661
You can read more about CSS selectors here: http://css-tricks.com/child-and-sibling-selectors/