I want to remove the bottom margin of a title
only in case it has a subtitle
next to it.
Probably related to Is there a "previous sibling" selector? but that question does not answer my question.
.title, .subtitle {
border: 1px solid black
}
.title + .subtitle {
background: yellow;
margin-top: 0;
}
<header>
<h3 class="title">My title</h3>
<p class="subtitle">my subtitle: top space NOT OK!</p>
</header>
<p> some text lorep ipsum: top space OK</p>
<header>
<h3 class="title">My title</h3>
<p>my other text: top space OK</p>
</header>
my other text: top space OK
` _inside_ the `header`, whereas in the first one, the text came _after_ the header, and only title and subtitle are part of the header? If that wasn't the case - then you could just disable the margins of the h3 and p _inside_ the header, and give header a margin-bottom instead. – CBroe Oct 14 '22 at 11:18