How to write fraction value using html?

后端 未结 9 929
闹比i
闹比i 2020-11-28 08:09

I want to write fraction value such as the picture below:

\"enter

How do I wri

相关标签:
9条回答
  • 2020-11-28 08:37

    Using pure html and with margin property of br you can work around

    br {   
        content: "";
        margin: -1%;
        display: block;
     }
    <big>1</big><sup> <u><big>1</big></u></sup><br/>&nbsp;&nbsp;<sup> <big>2</big></sup>

    0 讨论(0)
  • 2020-11-28 08:42

    The following code will be rendered just as the example in the question, and if the client does not support CSS it will be rendered as plain text, still readable as a fraction:

    <p>1 <span class="frac"><sup>12</sup><span>/</span><sub>256</sub></span>.</p>
    
    span.frac {
      display: inline-block;
      font-size: 50%;
      text-align: center;
    }
    span.frac > sup {
      display: block;
      border-bottom: 1px solid;
      font: inherit;
    }
    span.frac > span {
      display: none;
    }
    span.frac > sub {
      display: block;
      font: inherit;
    }
    

    The middle <span> serves only for the clients who do not render CSS - the text is still readable as 1 12/256 - and that's why you should place a space between the integer and the fraction.

    You may want to change the font-size, because the resulting element may be a little taller than the other characters in the line, or you may want to use a relative position to shift it a little to the bottom.

    But the general idea, as presented here, may be enough for the basic use.

    0 讨论(0)
  • 2020-11-28 08:42
    br {   
        content: "";
        margin: -1%;
        display: block;
     }
    
    <big>1</big><sup> <u><big>1</big></u></sup><br/>&nbsp;&nbsp;<sup> <big>2</big></sup>
    
    0 讨论(0)
提交回复
热议问题