div~div 和 div:not(:first-of-type) 有什么区别?
javascriptweb developmentfront end scripts
两者在匹配元素方面是相同的。我们来看一个例子:
<section> <div></div> <!-- div:first-child or div:first-of-type --> <div></div> <!-- div+div or div~div or div:nth-of-type(2) --> <p></p> <div></div> <!-- div+p+div or div~div or div:nth-of-type(3), but not div+div --> </section> <section> <h1></h1> <!-- h1:first-child --> <div></div> <!-- div:first-of-type or div:nth-child(2) --> <div></div> <!-- div~div or div:nth-of-type(2) or div:nth-child(3) --> </section>
如果您的 CSS 规则中的两个选择器都与相同元素匹配,则 div: not(:first-of-type) 将因:first-of-type 伪类而获得优先权。