I have two span
s on adjacent lines, with their background-color
set. Unfortunately this leaves a gap between the two lines:
html {
line-height: 1.5;
}
span {
background-color: red;
}
<pre>
<span>line 1</span>
<span>line 2</span>
</pre>
Is it possible, by only changing the style used for span
, to extend the colored background vertically so that it fills the gap?
One thing I’ve tried using is padding: ... 0;
, but it’s not clear what value to use for ...
in order to be robust against changes in font-size
and/or line-height
.
4
Answers
Making
line-height: 1;
does that job.Another way would be of to remove style from
html
.I think
display: inline-block;
will do the trick.I would just wrap in a flex div to ensure it always works as expected.
You could add a pseudo after element to all but the final span and give that the same background color and if you give it a line height of 1 it will be large enough to cover the gap. Position it just below the span element so any padding is taken care of.