Home > Article > Web Front-end > What are the basic selectors in css?
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 class btn
. ID Selector
#id_name
: Selects elements with the specified ID. For example, #header
selects the element with the ID header
. Descendant selector
ancestor_element descendant_element
: Selects descendant elements that belong to the specified ancestor element. For example, body .btn
selects all elements that are body
elements and have the class btn
. Child element selector
: Selects child elements that directly belong to the specified parent element. For example,
ul > li selects all
li elements that are directly part of the
ul element.
Adjacent sibling element selector
p h2
selects the h2
element immediately following the p
element.
p ~ h2
selects all h2
elements that are adjacent to a p
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!