subscript and superscript for the same element

前端 未结 2 559
孤街浪徒
孤街浪徒 2021-02-07 06:50

Is there any way to add both subscript and and superscript to the same element? If I do

Sample TextSubSup


        
相关标签:
2条回答
  • 2021-02-07 07:01

    This one is similar to CyberDudes approach, additionally it indents the following text depending on the width of sub and sup:

    http://jsfiddle.net/jwFec/1/

    Some text <span class="supsub"><sup>sup</sup><sub>sub</sub></span> followed by other text.<br />
    
    <style>
    .supsub {
        display: inline-block;
    }
    
    .supsub sup,
    .supsub sub {
        position: relative;
        display: block;
        font-size: .5em;
        line-height: 1.2;
    }
    
    .supsub sub {
        top: .3em;
    }
    </style>
    
    0 讨论(0)
  • 2021-02-07 07:02

    I'm no CSS guru but you could try something along the lines of http://jsfiddle.net/TKxv8/1/

    There are a lot of hardcoded values and the effects on other elements around may only be found afterwards but it's a good place to start.

    Sample Text 
    <span class='supsub'>
        <sup class='superscript'>Sup</sup>
        <sub class='subscript'>Sub</sub>
    </span>
    
    .supsub {position: absolute}
    .subscript {color: green; display:block; position:relative; left:2px; top: -5px}
    .superscript {color: red; display:block; position:relative; left:2px; top: -5px}
    
    0 讨论(0)
提交回复
热议问题