If I have a <sup>
tag in a multi-line <p>
tag, the line with the superscript on it has a larger line spacing above it than the other lines, irregardless of what line-height I put on the <p>
.
Edit for clarification: I don't mean i have lots of <p>
s, each which is on a single line. I have a single <p>
with enough content in it to cause wrapping onto multiple lines. Somewhere (anywhere) in the text there may be a <sup>
or <sub>
. This affects the line height for that line by adding extra spacing above/below. If I set a larger line-height on the <p>
this makes no difference to the problem. The line-height is increased, but the extra spacing still remains.
How can I make it consistent - i.e. all lines have the same spacing whether they contain a <sup>
or not?
Your solutions must be cross-browser (IE 6+, FF, safari, opera, chrome)
I prefer the solution suggested here, as exemplified by this jsfiddle:
CSS:
HTML:
The beauty of this solution is that you can tailor the vertical positioning of the superscript and subscript, to avoid any clashes with the line above or below... in the above, just increase or decrease the
0.2em
to suit your requirements.To make all lines taller, to look the same as the line with the superscript, define a larger
line-height
for the entire paragraphor whatever value gives the effect you desire.
It may look strange, but that's how you described your requirements.
EDIT: In order to make all lines look the same when only one needs more vertical space than the others, ALL lines in the paragraph will have to be taller.
This, as I said, may not an attractive solution. Maybe something can be done with a span making just the text with the sub/superscript smaller, apart from that I don't believe what you want can be achieved. But I'd like to see someone else's solution.
EDIT2: Incidentally, I've tried a small html file containing
And the lines are all the same height in FF3.0.14 and Konqueror (I can't speak for other browsers)
I've been using line-height: normal for the superscript, which works fine for me in Safari, Chrome, and Firefox, but I'm not sure about IE.
I prefer to use
length
on the vertical-align. This aligns the baseline of the element at the given length above the baseline of its parent.¹, ² etc. might do the trick. it's an HTML trick to superscript
I had the same problem and non of the given answers worked. But I found a git commit with a fix that did work for me: