HTML tag affecting line height, how to make

2020-02-02 04:07发布

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)

14条回答
我想做一个坏孩纸
2楼-- · 2020-02-02 04:33
sup {
        font-size: 0.83em;
        vertical-align: super;
        line-height: 0;
    }

The trick is to set the <sup>'s line-height to 0. @Scott said to use normal, but this doesn't always work.

This means you don't have to change the line-height of surrounding text to accommodate the superscript text. I've tested this in IE7+ and the other major browsers.

查看更多
乱世女痞
3楼-- · 2020-02-02 04:33

keep it easy:

sup { vertical-align: text-top; }

[font-size dependent on your individual type-face]

查看更多
手持菜刀,她持情操
4楼-- · 2020-02-02 04:33

Specially use this on newsletter -

<sup style="font-size:9px; line-height:8px;">&reg;</sup>
查看更多
The star\"
5楼-- · 2020-02-02 04:33

Answer from here, works in both phantomjs and in email-embedded HTML:

Lorem ipsum <sup style="font-size: 8px; line-height: 0; vertical-align: 3px">&reg;</sup>

查看更多
走好不送
6楼-- · 2020-02-02 04:37

The reason why the <sup> tag is affecting the spacing between two lines has to do with a number of factors. The factors are: line height, size of the superscript in relation to the regular font, the line height of the superscript and last but not least what is the bottom of the superscript aligning with... If you set... the line height of regular text to be in a "tunnel band" (that's what I call it) of 135% then regular text (the 100%) gets white padded by 35% of more white. For a paragraph this looks like this:

 p
    {
            line-height: 135%;
    }

If you then do not white pad the superscript...(i.e. keep its line height to 0) the superscript only has the width of its own text... if you then ask the superscript to be a percentage of the regular font (for example 70%) and you align it with the middle of the regular text (text-middle), you can eliminate the problem and get a superscript that looks like a superscript. Here it is:

sup
{
    font-size: 70%;
    vertical-align: text-middle;
    line-height: 0;
}
查看更多
你好瞎i
7楼-- · 2020-02-02 04:41
sup, sub {
  vertical-align: baseline;
  position: relative;
  top: -0.4em;
}
sub { 
  top: 0.4em; 
}
查看更多
登录 后发表回答