Superscript in CSS only?

后端 未结 15 1436
花落未央
花落未央 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 16:08

    This is another clean solution:

    sub, sup {vertical-align: baseline; position: relative; font-size: 70%;} /* 70% size of its parent element font-size which is good. */
    sub {bottom: -0.6em;} /* use em becasue they adapt to parent font-size */
    sup {top: -0.6em;} /* use em becasue they adapt to parent font-size */
    

    In this way you can still use sup/sub tags but you fixed their idious behavior to always screw up paragraph line height.

    So now you can do:

      

    This is a line of text.

    This is a line of text, with sub text.

    This is a line of text, with sup text.

    This is a line of text.

    And your paragraph line height should not get screwed up.

    Tested on IE7, IE8, FF3.6, SAFARI4, CHROME5, OPERA9

    I tested using a p {line-height: 1.3;} (that is a good line height unless you want your lines to stick too close) and it still works, cause "-0.6em" is such a small amount that also with that line height the sub/sub text will fit and don't go over each other.

    Forgot a detail that might be relevant I always use DOCTYPE in the 1st line of my page (specifically I use the HTML 4.01 ). So I don't know if this solution works well when browser is in quirkmode (or not standard mode) due to lack of DOCTYPE or to a DOCTYPE that does not triggers Standard/Almost Standard mode.

提交回复
热议问题