To get the immediate child element, not any child.
For example:
.avo
{
background-color:red;
height:50px;
}
.avo > .pai > .filho {
color:red;
background-color:yellow;
height:20px;
}
.avo .filho{
background-color:green;
color:white;
}
<div class="avo">
<div class="pai">
<div class="filho">Eu sou o filho</div>
</div>
<div class="filho">Eu sou o filho</div>
</div>
This is very useful in case of menus where you do not want a definition, even made directly in tags, not applied to all elements.
Example:
nav.menu > ul{}
nav.menu > ul > li {}
If I have to put another ul
to create a submenu within the li of the .menu
class, it will not interfere, since the css is set to the immediate child of nav.menu
( nav.menu > ul
) and not for any% of% within% of% (% with%).
So summarizing the difference between the two forms could be put like this:
ul
= Immediate child
nav.menu
= Any child