I have a problem with the line-height
style in paragraphs filled with a span
, when the font size in the span
is smaller than that of the paragraph.
My Angular application has an editable div
element, and I use the Froala editor API commands to allow formatting. I added my own custom commands to modify the line-height
in paragraphs.
The CSS sets a default font size and line height for the editor:
div {
font-size: 20px;
line-spacing: 1.25;
}
The initial markup is something like this:
<div>
<p>Some long text that wraps here...</p>
<p>Some long text that wraps here...</p>
<p>Some long text that wraps here...</p>
</div>
After setting the font size and line height with the editor, the markup becomes:
<div>
<p style="line-height: 1;"><span>Some long text that wraps here...</span></p>
<p style="line-height: 1;"><span style="font-size: 8px;">Some long text that wraps here...</span></p>
<p style="line-height: 1;"><span style="font-size: 40px;">Some long text that wraps here...</span></p>
</div>
As long as the font size in the span
is equal or larger than the font size of the paragraph (in the present case, 20px
), the line height scales correctly. However, when the font size in the span
is smaller than that of its paragraph, the line height does not scale as it should. The problem can be seen in this jsfiddle.
If I set display: inline-block
on the span
elements, the line height scales properly but that display setting messes up the wrapping in the editor. Otherwise, the only workaround that I can think of is to use data binding to set the line height with pixel units, after retrieving the font size inside of the paragraph. Is there a simpler way to force the line height to adjust to span
elements with a smaller font size?