問題描述
用逗號(hào)分隔的 CSS 選擇器部分的正確術(shù)語是什么?
What is the correct term for the sections of CSS selectors that are separated by commas?
body.foo .login , body.bar .login { ... }
/* |
Part 1 | Part 2 */
在這些部分中,由組合符分隔的部分(空格、+
、>
等)的術(shù)語是什么?
Within those sections, what is the term for the parts separated by combinators (spaces, +
, >
, etc)?
body.foo .login , ... { ... }
/* |
Part 1 | Part 2 */
推薦答案
用逗號(hào)分隔的 CSS 選擇器部分的正確術(shù)語是什么?
What is the correct term for the sections of CSS selectors that are separated by commas?
這些被稱為復(fù)雜選擇器.整個(gè)以逗號(hào)分隔的列表稱為選擇器列表.
在這些部分中,由組合符分隔的部分(空格、+
、>
等)的術(shù)語是什么?
Within those sections, what is the term for the parts separated by combinators (spaces,
+
,>
, etc)?
這些被稱為 復(fù)合選擇器.
These are known as compound selectors.
因此,選擇器列表由一個(gè)或多個(gè)用逗號(hào)分隔的復(fù)雜選擇器組成,每個(gè)復(fù)雜選擇器由兩個(gè)主要部分組成:復(fù)合選擇器和組合器.它還可以選擇包含偽元素.
So, a selector-list is made up of one or more complex selectors separated by commas, and each complex selector is made up of two main parts: compound selectors, and combinators. It can also optionally contain pseudo-elements.
復(fù)合選擇器曾經(jīng)有一個(gè)相當(dāng)復(fù)雜的名稱簡單選擇器序列".更糟糕的是,復(fù)雜的選擇器只是被稱為選擇器".不用說,我建議使用新術(shù)語,因?yàn)榕c它們的前輩相比,它們更直接、更簡潔且完全不含糊.
Compound selectors used to have the rather convoluted name "sequence of simple selectors". Worse still, complex selectors were just called "selectors". Needless to say, I recommend using the new terms as they are much more straightforward, much less cumbersome and completely unambiguous compared to their predecessors.
既然我在這里,這里是其余的定義......
And since I'm here, here are the rest of the definitions...
簡單的選擇器是選擇器的基本組成部分.它是以下任何一種:
A simple selector is one fundamental component of selectors. It is any one of the following:
- 通用選擇器 (
*
),可選地帶有命名空間 - 類型選擇器(
a
、div
、span
、ul
、li
等),可選地使用命名空間 - 屬性選擇器(
[att]
、[att=val]
等)、可選的命名空間 - 類選擇器(
.class
) - ID 選擇器 (
#id
) - 偽類(
:偽類
)
- Universal selector (
*
), optionally with a namespace - Type selector (
a
,div
,span
,ul
,li
, etc), optionally with a namespace - Attribute selector (
[att]
,[att=val]
, etc), optionally with a namespace - Class selector (
.class
) - ID selector (
#id
) - Pseudo-class (
:pseudo-class
)
如上所述,復(fù)合選擇器(以前稱為簡單選擇器序列")是不由組合器分隔的簡單選擇器鏈:
As answered above, a compound selector (formerly a "sequence of simple selectors") is a chain of simple selectors not separated by a combinator:
a:not([rel="external"]):hover
組合器是選擇器的另一個(gè)基本組成部分.它是分隔兩個(gè)復(fù)合選擇器的符號(hào)或標(biāo)記,在其位置建立由兩個(gè)復(fù)合選擇器表示的兩個(gè)元素之間的關(guān)系.目前有四種組合器在使用:
A combinator is another fundamental component of selectors. It is a symbol or token that separates two compound selectors, establishing in its place a relationship between the two elements represented by the two compound selectors. There are currently four combinators in use today:
后代組合子:
Descendant combinator:
article p
子組合子:
Child combinator:
/*
* The extra spaces in between are whitespace,
* and are therefore insignificant.
*/
ul > li
相鄰兄弟組合子:
Adjacent sibling combinator:
header + section
通用兄弟組合子:
General sibling combinator:
h2 ~ p
更多的組合子可能會(huì)在以后的規(guī)范中引入.
More combinators may be introduced in later specifications.
而復(fù)合選擇器(以前只是選擇器")是由組合器鏈接的復(fù)合選擇器組成的完整字符串:
And a complex selector (formerly just "selector") is a complete string made up of compound selectors linked by combinators:
nav[role="main"] > ul:first-child > li
復(fù)合選擇器的主題是它的最后一個(gè)或唯一的復(fù)合選擇器,表示將被匹配或設(shè)置樣式的元素.在上面的例子中,選擇器的主題是 li
.
The subject of a complex selector is its last, or only, compound selector, representing the element that will be matched or styled. In the above example, the subject of the selector is li
.
術(shù)語 selector 已被概括,因此為了簡單明了,它現(xiàn)在可以指代以下任何一個(gè),以及它指的是哪個(gè)to 在任何給定時(shí)刻都應(yīng)該從上下文中收集:
The term selector has been generalized, so it may now refer to any of the following for the purposes of simplicity and brevity, and which one it's referring to at any given moment should be gleaned from context:
- 簡單的選擇器
- 復(fù)合選擇器
- 復(fù)雜選擇器
- 選擇器列表(例如樣式規(guī)則的選擇器"組件)
一些個(gè)人筆記:
術(shù)語鍵選擇器"是瀏覽器供應(yīng)商創(chuàng)造的,用于選擇器實(shí)現(xiàn),并不是一個(gè)官方術(shù)語.然而,它通常用于表示選擇器的主題",因?yàn)閷?shí)現(xiàn)碰巧使用選擇器的主題作為確定匹配的關(guān)鍵.
The term "key selector" was coined by browser vendors for use with selector implementations, and is not an official term. It is often used to mean "subject of the selector" however, because implementations happen to use the subject of the selector as the key for the purposes of determining matches.
pseudo-selector"這個(gè)詞是作者為了混合偽類和偽元素而創(chuàng)造的,它不是一個(gè)官方的,也不是真正有意義的術(shù)語.盡管您可以在一些早期的 W3C CSS2/3 草案中找到它,但這可能是一個(gè)錯(cuò)誤.請不要使用這個(gè)詞,因?yàn)樗槐匾貏?chuàng)建試圖將兩個(gè)完全不同的概念歸為一個(gè)總稱來混淆.
The term "pseudo-selector" was coined by authors to mix pseudo-classes and pseudo-elements, and is not an official, or indeed meaningful, term. Although you can find it in some early-stage W3C CSS2/3 drafts, that was probably a mistake. Please don't use this term, as it needlessly creates confusion by attempting to group two completely different concepts into a single umbrella term.
偽元素(::pseudo-element
)不是簡單的選擇器,因此不能出現(xiàn)在只能匹配實(shí)際元素的地方.但是,出于 CSS 解析的目的,它們?nèi)员灰暈檫x擇器,并且如上所述,目前可以出現(xiàn)在列表中任何復(fù)雜選擇器的末尾(即,在每個(gè)復(fù)雜選擇器的最后一個(gè)或唯一一個(gè)復(fù)合選擇器的末尾).
Pseudo-elements (::pseudo-element
) are not simple selectors, and therefore cannot appear in places where only actual elements may be matched. However, they are still considered selectors for the purposes of CSS parsing, and as stated above currently can appear at the end of any complex selector in a list (i.e. at the end of the last, or only, compound selector of each complex selector).
在 CSS 中,一個(gè)典型的樣式規(guī)則(以前稱為規(guī)則集")由一個(gè)選擇器和一個(gè)聲明塊組成.
In CSS, a typical style rule (formerly "ruleset") consists of a selector and a declaration block.
命名空間前綴本身不是選擇器,但它們可以應(yīng)用于類型選擇器、通用選擇器和屬性選擇器,以匹配文檔中已(或未)命名空間的組件.
Namespace prefixes are not selectors in their own right, but they may be applied to type selectors, universal selectors and attribute selectors to match components in a document that are (or are not) namespaced.
選擇器的特異性目前僅指一個(gè)復(fù)雜的選擇器.匹配規(guī)則時(shí),列表中與給定元素匹配的任何復(fù)雜選擇器都將被考慮用于特異性計(jì)算.如果多個(gè)復(fù)雜選擇器與一個(gè)元素匹配,則將使用最具體的選擇器進(jìn)行計(jì)算.
The specificity of a selector currently only refers to that of a single complex selector. When matching rules, any of the complex selectors in a list that match a given element will be considered for specificity calculations. If more than one complex selector matches an element, the most specific one will be used for calculations.
對于某些 4 級(jí)選擇器,特異性將是一個(gè)更復(fù)雜的問題,例如 :is()
和增強(qiáng)的 :not()
,以及 of增強(qiáng)的
表示法.:nth-child()
偽中的 S
Specificity will be a more complicated issue with some level 4 selectors, such as :is()
and the enhanced :not()
, and the of S
notation in the enhanced :nth-child()
pseudo.
這篇關(guān)于選擇器部分和部分的正確術(shù)語和單詞的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!