Manwal ng Combiner ng CSS

CSS Combinators

A combinator is a symbol used to explain the relationship between selectors.

The following table shows the different combinators in CSS:

Name Symbol Example Example description
Child combinator > div > p Select all <p> elements that are direct children of a <div> element.
Descendant combinator (single space) div p Select all <p> elements within a <div> element.
Namespace separator | ns | h2 Select all <h2> elements in the namespace ns.
Adjacent sibling combinator + div + p Select the first <p> element immediately following a <div> element.
Selector list , div, p 选择所有 <div> 元素和所有 <p> 元素。
后续兄弟组合器 ~ p ~ ul 选择所有前面有 <p> 元素的 <ul> 元素。