I want to add a bottom margin to the last paragraphs. It should be selected if there are other element types after the paragraph. For visual purpose I will use red backgrounds in my example. I would like the <p>
before the second <h2>
to be also red. I can't see how to select this element. :nth-child()
will not work, as the number of elements could vary. Thank you!
p:last-of-type {
background: red;
}
<h2>Title</h2>
<p>This should not be red</p>
<p>This should be red</p>
<h2>Title</h2>
<p>This should not be red</p>
<p>This should be red</p>