1. div >a
这个选择器将使我们能够选择所有父元素是div标签的元素。
<!-- This one will be selected -->
<div>
<a></a>
</div>
<!-- This one won't be selected -->
<p>
<a></a>
</p>
2. div +a
选择紧接在div元素之后的每个标签。如果我们在div和a标签之间有一个元素,则不会选择该元素。
<main>
<!-- This one will be selected -->
<div></div>
<a></a>
<!-- This one won't be selected -->
<div></div>
<p></p>
<a></a>
</main>
3. div ~a
a标签将选择每个标签,然后在同一级别上添加div标签。换句话说,如果a标签不是紧跟在div标签之后,而是具有div标签作为同级元素,则将选择该标签。
<main>
<!-- This one will be selected -->
<div></div>
<a></a>
<!-- This one will be selected -->
<div></div>
<p></p>
<a></a>
<section>
<!-- This one will be selected -->
<div></div>
<p></p>
<a></a>
</section>
<footer>
<!-- This one won't be selected -->
<p></p>
<a></a>
</footer>
</main>
4. [属性^=值]
例如:[class ^ =“ list-”]此选择器将选择每个包含class属性且其值以list-开头的元素。
<main>
<!-- This one will be selected -->
<div class="list-element"></div>
<!-- This one will be selected -->
<div class="list-container"></div>
<!-- This one will be selected -->
<div class="list-item"></div>
<!-- This one won't be selected -->
<div class="list__footer"></div>
</main>
5. [属性$=值]
例如:[src $ =“.png”]这将选择每个值以.png结尾的src属性。
<div>
<!-- This one will be selected -->
<img src="image1.png">
<!-- This one will be not selected -->
<img src="image2.jpg">
<!-- This one will be selected -->
<img src="image3.png">
<!-- This one won't be selected -->
<img src="image4.svg">
</div>
6. [属性=值]*
例如:[class * =“-list”]此选择器将选择其class属性包含-list的每个元素。 不管-list是在类值的开头,中间还是结尾都没有关系。最重要的是该值必须包含-list。
<main>
<!-- This one will be selected -->
<div class="main-list-container"></div>
<!-- This one will be selected -->
<div class="primary-list"></div>
<!-- This one will be selected -->
<div class="primary-list-item"></div>
<!-- This one won't be selected -->
<div class="list-footer"></div>
</main>
来源:CSDN
作者:W Y L
链接:https://blog.csdn.net/weixin_45959525/article/details/104858194