-
The
next-sibling combinator
(+
) separates two selectors and matches the second element only if it immediately follows the first element, and both are children of the same parent element
next-sibling combinator
(+
) separates two selectors and
matches the second element only if it immediately follows the first element, and
both
are children of the same parent element
Paragraph-1
Paragraph-2
Paragraph-3
<div class="combinators"> <p class="para1">Paragraph-1</p> <p class="para2">Paragraph-2</p> <p class="para3">Paragraph-3</p> </div>
.combinators { font-size: 1.4em; } .para1+p { color: red; text-align: right; } .para1~p { background-color: lightgoldenrodyellow; text-align: center; }
text-align:center
applies to the last two paragraphs
para1~p
overrides (in this case) para1+p