1. Type selector
Used to look for specific types of elements, generally referred to in CSS are commonly defined and widely used elements, such as paragraph, title, body, etc.
< is also called an element selector or a simple selector >
P{font-size:16px;color:black;}
2. Descendant selector
used to look for descendants of a particular element or group of elements, denoted by a space in the middle
Body p{font-size:14px;}
3. ID selector
Used to find the element with the specified ID, denoted by the character #
#intro {font-weight:bold;}
<p id= "Intro" >hello world!</p>
4. Class selector
Used to look for an element with the specified class name, by the point number.
. Date-posted{color: #ccc;}
<p class= "date-posted" >12/12/2012</p>
5. Pseudo-Class selector
apply a style to a particular state of the target element
Common:: link,:visited (link pseudo-class, can only be applied to anchor elements)
: Hover,:active,:focus (Dynamic Pseudo-class, theoretically applicable to any element)
A:link{color:blue;text-decoration:none;}
A:visited{color:grey;}
a:hover,:active,:focus{color:red;}
6. Universal Selector
Matches all available elements, represented by *
*{padding:0;margin:0;}
7. Advanced Selector
1) Sub-selector
Select only the immediate descendants of the element, that is, the child element, the definition symbol is >
Body>p{color:green;}
<body>
<p> This paragraph is green </p>
<div><p> This paragraph is not green </p></div>
<p> This paragraph is green </p>
</body>
2) adjacent sibling selector (adjacent selector)
Locates the element after an element under the same parent element, the definition symbol is +
h2+p{color:red;}
<p> is red </p>
<p> not red </p>
<div><p> not red </p></div>
<p> not red </p>
It's not red.
<p> Red </p>
<p> not Red </p>
3) Property Selector
Looking for an element based on whether a property exists or the value of the property, defined by writing the property and value in []
a[name]{color:red}/* Select the A element with the name attribute */
[Special]/* Select any element with the Special property */
img[alt= "So"][class= "pic"]{margin:20px;}/* Match two properties and values simultaneously */
[special~= "Wo"] {color:red;}
Common selectors