CSS selectors are used to select and manipulate HTML elements, including: Universal selectors: select all elements. Element selector: Selects the element with the specified element name. Class selector: selects elements with the specified class name. ID selector: Selects elements with a specified ID. Descendant selector: Selects descendant elements that belong to the specified ancestor element. Child element selector: Selects child elements that directly belong to the specified parent element. Adjacent sibling selector: Selects the sibling element immediately following the specified sibling element. Universal sibling selector: Selects all sibling elements adjacent to the specified element.
CSS Basic Selector
CSS selector is used to select and manipulate HTML elements in HTML documents. There are several different CSS selector types, each serving a specific purpose.
Universal Selector
*
: Select all elements.Element selector
element_name
: Selects elements with the specified element name. For example,p
selects all paragraph elements.Class selector
.class_name
: Selects elements with the specified class name. For example,.btn
selects all elements with classbtn
.ID Selector
#id_name
: Selects elements with the specified ID. For example,#header
selects the element with the IDheader
.Descendant selector
ancestor_element descendant_element
: Selects descendant elements that belong to the specified ancestor element. For example,body .btn
selects all elements that arebody
elements and have the classbtn
.Child element selector
: Selects child elements that directly belong to the specified parent element. For example,
ul > liselects all
lielements that are directly part of the
ulelement.
Adjacent sibling element selector
p h2
selects theh2
element immediately following thep
element.
p ~ h2
selects allh2
elements that are adjacent to ap
element.
The above is the detailed content of What are the basic selectors in css?. For more information, please follow other related articles on the PHP Chinese website!