简体   繁体   English

组合选择器“ AB”如何工作? 其中“ A”和“ B”是任何选择器?

[英]How does combination selector “AB” works? where “A” and “B” is any selector?

I have been studying "combination selector" using MDN . 我一直在研究使用MDN的 “组合选择器”。 It means that by placing A and B together (where A and B can be any selector), it select any element matching both A and B at the same time. 这意味着通过将A和B放在一起(其中A和B可以是任何选择器),它可以同时选择与A和B都匹配的任何元素。

Could someone please explain how it actually works? 有人可以解释一下它是如何工作的吗?

I understand how other combination selector ie "AB", "A > B", "A + B" and "A ~ B" works, but is stack on how "AB" works. 我了解其他组合选择器(即“ AB”,“ A> B”,“ A + B”和“ A〜B”)如何工作,但是堆叠在“ AB”的工作方式上。

在此处输入图片说明

It simply means an element would need to have both classes to be matched. 这只是意味着一个元素将需要同时匹配两个类。 For example 例如

<div class="A B">

This would be selected by the rule 这将由规则选择

.A.B { //rules }

The class names in the element must be separated by a space, but the CSS selector would not have a space between the class names. 元素中的类名称必须用空格分隔,但是CSS选择器之间的类名称之间不能有空格。 That would be the second case in your table example, and a different situation. 那将是表示例中的第二种情况,并且情况不同。

You take any two selectors, and you write them together without anything between them. 您可以选择两个选择器,然后将它们写在一起,而在它们之间没有任何选择。

For example, let A be the type selector for <a> elements and B be the :focus pseudo-class selector. 例如,令A<a>元素的类型选择器,而B:focus伪类选择器。

a:focus

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM