I'm having trouble setting up a universal stylesheet where I need to set up different spacings between different elements, depending on what follows that element?
For example, if I have an <h1>
followed by an <h2>
, that's going to have different spacing than an <h2>
followed by a <p>
.
I can't just add the same spacing after <h1>
, because it will be different depending on what follows.
The only thing I am aware of is this...
But, in this case, the 30px margin is added after the p, but not between the h1 and the p.
h1 + p {
margin-bottom: 30px;
}
h1 + ul {
margin-bottom: 30px;
}
<h1>Hello</h1>
<p>World</p>
<hr>
<h1>Hello</h1>
<ul>
<li>Real</li>
<li>World</li>
</ul>
I'm trying to write styles based on what follows each element. I hope that makes sense.