Can you explain the variation between these two CSS selectors? When using them, I seem to receive the same outcome.
In the HTML:
<div>One</div>
<p>Two</p>
div+p {
background:red;
}
This code assigns a red background to the <p>
element.
div~p {
background:red;
}
Similarly, this code also provides a red background for the <p>
element.
What exactly sets these two selectors apart?