我今天看到了.class1~.class2选择器,不得不查找它.
div ~ p {}
选择每个< p>以< div>开头的元素元件.换一种说法,
<div></div> <p></p>
< p>< / p>会被选中,对吗?
然后是选择器:
div + p {}
选择所有< p>紧跟在< div>之后的元素元素.换一种说法,
<div></div> <p></p>
我是否认为这些是等价的,或者我错过了什么?
解决方法
在您的特定方案中,这两个选择器是等效的,但不是在更一般的情况下.
有一个重要的区别,组合者说:
The elements represented by the two sequences share the same parent in
the document tree and the element represented by the first sequence
immediately precedes the element represented by the second one.
想象一下这种情况:
<div></div> <p></p> <!-- this will be selected with the + combinator --> <p></p> <!-- these two paragraphs will be affected by the ~ combinator --> <p></p> <!-- but NOT by the + combinator -->
请不要混淆W3C,一个标准化网络技术的严肃机构,与w3schools相当07.02!