Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

css - Does the term adjacent selector exist?

MDN in this link talks about using adjacent sibling combinator and the specs. talk about combinators too but they never call the two selectors combined by the adjacent combinator a selector. People commonly call the result of the adjacent combinator an adjacent selector, is that informal use of the term?

question from:https://stackoverflow.com/questions/66057477/does-the-term-adjacent-selector-exist

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The terms "child selector" and "adjacent sibling selector" were old terminology used by the CSS2 spec when "selector" was a much looser term (it still is, but they use it more consistently now). It's related to "contextual selector" which is what CSS1 called selectors that used the descendant combinator. CSS2 introduced the term "combinator" to refer to the symbols themselves, but combinators themselves technically aren't selectors because they don't select anything on their own; instead, they indicate relationships between two (or more) selectors. MDN is not really correct in calling combinators selectors, but then again, it's all just semantics.

To answer your question, yes, "adjacent sibling selector" is an informal term. You can probably get away with using it even today, as it's easier to say by far than something like "a pair of compound selectors with the adjacent sibling combinator". Selectors 4 uses the much clearer and unambiguous name "next-sibling combinator" by the way.

To put it into examples:

  • + is the adjacent sibling combinator (next-sibling combinator in Selectors 4), and
  • E + F is an adjacent sibling selector (next-sibling selector) matching any F that directly follows an E.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...