Home  >  Article  >  Web Front-end  >  CSS combination selector_html/css_WEB-ITnose

CSS combination selector_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:43:52940browse

1. Space Select all descendant elements

div p

{
background-color:yellow;
}

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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn