div > p {
background-color: yellow;
}
doesn't appear to evaluate any differently than
div p {
background-color: yellow;
}
But would there be an effect I am unaware of? It seems that using the > is more proper style, at least.
div > p {
background-color: yellow;
}
doesn't appear to evaluate any differently than
div p {
background-color: yellow;
}
But would there be an effect I am unaware of? It seems that using the > is more proper style, at least.
There is a difference; >
is "immediately follows". So your div > p
would apply to the p
here:
<div>
<p>Text here</p>
</div>
but not here:
<div>
<table>
<tr>
<td>
<p>Text here</p>
</td>
</tr>
</table>
</div>
A more detailed description can be found within the CSS specification for child selectors.
Look at this example it might help you ...
div#container > ul {
border: 1px solid black; }
.......
<div id="container"> <ul>
<li> List Item
<ul>
<li> Child </li>
</ul>
</li>
<li> List Item </li>
<li> List Item </li>
<li> List Item </li> </ul> </div>
A selector of #container > ul will only target the uls which are direct children of the div with an id of container. It will not target, for instance, the ul that is a child of the first li.
For this reason, there are performance benefits in using the child combinator. In fact, it's recommended particularly when working with JavaScript-based CSS selector engines. ....... Read this : http://code.tutsplus.com/tutorials/the-30-css-selectors-you-must-memorize--net-16048 it will help you .
div > p
selects the direct child p
(only the sons),
div p
selects all its children p
, now matter how deep it is in the hierarchy (including the grandsons and great grandsons).
div>p
indicates a P which is a DIRECT child of div
div p
indicates a p that is descendent of div, not
Check Fiddle for example.