I would like to have a spacing between a h1
and a span
, which should be 30px
. It should be 30px
from the bottom of the letters from the h1
to the top of the letters of the span
, which comes below the h1
, here a picture where the spacing of 30px
should be (blue box shows spacing):
My h1
and span
have some line-height
. I made a border
around it, so the line-height
is visible. If I set now a margin-bottom
of 30px
to the h1
it looks like this:
The spacing begins at the end of the h1
element and ends at the start of the span
element. The line-height
is between the start/end of the element and the letters. So the spacing includes also the line-height
and it is not exactly 30px
. What's the best way to solve this? I know, that I could set the margin-bottom
like this: margin-bottom: 30px - [LINE-HEIGHT];
But how can I know, how much the two red boxes (line-heights) are, to subtract it correctly so that the spacing becomes exactly 30px
?
h1 {
font-family: Arial;
font-size: 45px;
line-height: 54px;
letter-spacing: 0;
color: darkred;
border: 1px solid black;
margin: 0 0 30px;
}
span {
font-family: Arial;
font-size: 30px;
line-height: 39px;
letter-spacing: 0;
color: gray;
border: 1px solid black;
}
<h1>Default main title</h1>
<span>Proin eget tortor risus. Vivamus magna justo, lacinia</span>
Here is my codepen example: https://codepen.io/STWebtastic/pen/QarjJO
I hope this is clear enough.