Superscript in CSS only?

后端 未结 15 1431
花落未央
花落未央 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:51

    Honestly I don't see the point in doing superscript/subscript in CSS only. There's no handy CSS attribute for it, just a bunch of homegrown implementations including:

    .superscript { position: relative; top: -0.5em; font-size: 80%; }
    

    or using vertical-align or I'm sure other ways. Thing is, it starts to get complicated:

    • CSS superscript spacing on line height;
    • Beware CSS for Superscript/Subcript on why you arguably shouldn't style superscript/subscript with CSS at all;

    The second point is worth emphasizing. Typically superscript/subscript is not actually a styling issue but is indicative of meaning.

    Side note: It's worth mentioning this list of entities for common mathematical superscript and subscript expressions even though this question doesn't relate to that.

    The sub/sup tags are in HTML and XHTML. I would just use those.

    As for the rest of your CSS, the :after pseudo-element and content attributes are not widely supported. If you really don't want to put this manually in the HTML I think a Javascript-based solution is your next best bet. With jQuery this is as simple as:

    $(function() {
      $("a.external").append("+");
    };
    

提交回复
热议问题