Home > Article > Web Front-end > What are the commonly used selectors in css?
Commonly used selectors in CSS include: class selector, ID selector, element selector, descendant selector, child selector, wildcard selector, group selector and attribute selector, used to specify Specific elements or groups of elements to enable styling and page layout.
CSS Common Selectors
CSS selectors are used to specify specific elements or groups of elements. The following are some of the most commonly used selectors in CSS:
1. Class selector
.class-name
.red
Select all elements with the "red" class. 2. ID selector
#id-name
#header
Select the element with ID "header". 3. Element selector
element-name
p
Selects all paragraph elements. 4. Descendant selector
parent > child
div > p
Selects all paragraph elements within the div element. 5. Child selector
parent child
ul li
Selects all list items (li) in the unordered list (ul). 6. Wildcard selector
*
* { color: blue; }
Set the text color of all elements to blue. 7. Group selector
element1, element2, element3
p, h1, h2
Select all paragraph, heading 1 and heading 2 elements. 8. Attribute selector
[attribute]
or [attribute=value]
[data-type="nav"]
Select all elements with "data-type " attribute and its value is "nav". The above is the detailed content of What are the commonly used selectors in css?. For more information, please follow other related articles on the PHP Chinese website!