Inline-block elements default to the height of their container's line height - when they have content. I'm finding that empty and whitespace-only inline block elements default to height:0 (this is on Firefox).
Is there a way I can make inline block elements that are empty gain the height of their container's line height the same as inline block elements that contain text?
Hardcoding the height isn't an option, nor is adding random HTML like
to make the elements not "empty". I've looked for duplicates and was surprised not to find any.
So for example, in this demo I'd like the first span (around a regular space) to appear how the second span (around a
) appears:
.inlineblock {
display: inline-block;
border: 2px solid #FF0000;
}
Lorem ipsum dolor sit amet, consectetur<span class="inlineblock"> </span>adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur<span class="inlineblock"> </span>sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
...rather than how it currently appears, which is like this, with the first span height:0:
I've tried: giving it a fixed width, height: auto;
, height: inherit;
, vertical align, and giving it a position:relative paragraph and/or inline-block container then height: 100%;
, but no success.
.inlineblock {
display: inline-block;
border: 2px solid #FF0000;
}
.width {
width: 5px;
}
.percent {
height: 100%;
}
.relative {
position: relative;
}
.vert {
vertical-align: top;
}
.auto {
height: auto;
}
.inherit {
height: inherit;
}
<p class="relative">Lorem ipsum dolor sit amet, consectetur<span class="inlineblock"> </span>adipiscing elit, sed do<span class="inlineblock percent"> </span>eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation<span class="relative"><span class="inlineblock percent"> </span></span>ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in<span class="inlineblock vert"> </span>voluptate velit esse<span class="inlineblock inherit"> </span>cillum dolore<span class="inlineblock auto"> </span>eu fugiat<span class="inlineblock width"> </span>nulla pariatur. Excepteur<span class="inlineblock"> </span>sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>