问题
What do you call these:
body > p + p
in a CSS selector? Are they:
- Relational operators
- Position-based criteria
- Something else?
I just have no idea what to call them. Is there an official name?
(And, also, are there official names for a b c
in a b c, d e f
and a
in a b c
?)
回答1:
According to http://www.w3.org/TR/CSS2/selector.html#selector-syntax they are called "combinators".
Thanks to Duncan Babbage for pointing out there are (or were) only three of them:
- space character = descendant
>
= child+
plus mark = adjacent following (next) sibling- And CSS3 adds a tilde
~
= general following sibling
回答2:
As identified by Tom Haws, the operators between the simple selectors are called combinators. In CSS2 there are only three: +
, >
and the space combinator.
- The space is the combinator used in a CSS descendent selector.
>
is the combinator used in a CSS child selector.+
is the combinator used in a CSS adjacent sibling selector.
In each case, the 'selector' is the full combination of the simple selectors and the combinators.
The range of valid CSS3 combinators is proposed to be expanded.
回答3:
The characters or whitespace between tag names are called combinators, see for example General Sibling combinator. These are >
and +
in your example.
The tags in your example are called simple selector in CSS2 and CSS3. If you would have a b c
that would be called sequence of simple selectors in CSS3 but simple selector in CSS2. The term simple selector does only refer to one element name in CSS3 such as a
in a b c
.
Or as the section Selector syntax states
A selector is a chain of one or more sequences of simple selectors separated by combinators.
a b c, d e f
is called the group of selectors where the group members are the selectors a b c
and d e f
. a b c
is a selector, or sequence of simple selectors, composed of the simple selectors a
, b
, c
combined by the combinator whitespace. The last sentence is only valid for CSS3.
来源:https://stackoverflow.com/questions/8370493/what-is-that-thing-between-css-selectors-called