There is no difference in terms of matching elements. Any div
that follows some other div
inside the same parent is not necessarily the first div
element inside its parent.
If the sibling selector was +
, not ~
, then div+div
has the added condition that the next element should appear immediately after the previous element. This does not apply to ~
- any number of brothers and sisters of any other kind may appear between them.
If the pseudo-class was :first-child
, not :first-of-type
, then div:not(:first-child)
would still match div:first-of-type
if the first div
inside its parent is not its first a descendant.
Here is an illustration:
<section> <div></div> <div></div> <p></p> <div></div> </section> <section> <h1></h1> <div></div> <div></div> </section>
There is a difference in terms of specificity . If you have CSS rules with two selectors matching the same elements, then div:not(:first-of-type)
will take precedence because of the :first-of-type
pseudo :first-of-type
. Please note that :not()
not taken into account - only its argument is considered.
Here is another illustration:
div { float: left; width: 50px; height: 50px; margin: 5px; border: 1px solid red; } div:not(:first-of-type) { border-color: green; } div ~ div { border-color: blue; }
<section> <div></div> <div></div> <div></div> </section>
source share