Superscript in CSS only?

后端 未结 15 1432
花落未央
花落未央 2020-11-29 15:20

How can I get superscript done, only in CSS?

I have a stylesheet where I mark the external links with a superscript character, but I\'m having a hard time getting th

15条回答
  •  旧巷少年郎
    2020-11-29 15:45

    I was working on a page with the aim of having clearly legible text, with superscript elements NOT changing the line's top and bottom margins - with the following observations:

    If for your main text you have line-height: 1.5em for example, you should reduce the line-height of your superscript text for it to appear correctly. I used line-height: 0.5em.

    Also, vertical-align: super works well in most browsers but in IE8 when you have a superscript element present, the rest of that line is pushed down. So instead I used vertical-align: baseline together with a negative top and position: relative to achieve the same effect, which seems to work better across browsers.

    So, to add to the "homegrown implementations":

    .superscript {
        font-size: .83em;
        line-height: 0.5em;
        vertical-align: baseline;
        position: relative;
        top: -0.4em;
    }
    

提交回复
热议问题