the accepted answer is outdated.
today, the correct answer would be to use the is pseudo-class which is now supported by all browsers:
support for is:
p {
margin: 0;
}
:is(p, div) + :is(p, div) {
margin-top: 24px;
}
<p>lorem ipsum</p>
<div>hello</div>
<p>consecetur loremis pestillis</p>
<div>world</div