Home > Article > Web Front-end > CSS combination selector_html/css_WEB-ITnose
1. Space Select all descendant elements
div p
{Select all descendants of div elements The p element can be a sub-element, a sub-sub element...
2. Greater than sign> Select all direct sub-level elements
div>p
{
background-color:yellow;
}
Select all direct child elements of the div element, only one level of child elements
3. Tilde~ Select all sibling elements on the same layer
div~p
{
background-color:yellow;
}
Select All sibling elements of the same layer of the div element
4. Plus sign selects the first sibling element of the same layer
div p
{
background-color:yellow;
}
Select the first sibling element of the same layer of the div element
5. p:first-child selects the first p element
p:first-child
{
color:blue;
}
selects the first one p element