How to write fraction value using html?

后端 未结 9 928
闹比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:17

    Using MathML (Specification, Wikipedia):

    <math>
     <mrow>
      <mn>1</mn>
      <mfrac>
       <mi>1</mi>
       <mi>2</mi>
      </mfrac>
     </mrow>
    </math>

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

    .frac {
        display: inline-block;
        position: relative;
        vertical-align: middle;
        letter-spacing: 0.001em;
        text-align: center;
    }
    .frac > span {
        display: block;
        padding: 0.1em;
    }
    .frac span.bottom {
        border-top: thin solid black;
    }
    .frac span.symbol {
        display: none;
    } 
    1 <div class="frac">
        <span>1</span>
        <span class="symbol">/</span>
        <span class="bottom">2</span>
        
    </div>

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

    You can use <sup> and <sub> elements in conjunction with the fraction slash entity &frasl;

    <sup>1</sup>&frasl;<sub>2</sub> is 12

    UPDATE: I made this fiddle that shows a hyphenated fraction in HTML using a table.

       <table>
          <tbody>
            <tr>
              <td rowspan="2">1</td>
              <td style="border-bottom:solid 1px">1</td>
              </tr>
              <tr>            
                <td>2</td>
              </tr>
          </tbody>
       </table>
    
    0 讨论(0)
  • 2020-11-28 08:23

    Try the following:

    1<sup>1</sup>&frasl;<sub>2</sub>

    This displays as:

    112

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

    I think there is an easier way for doing this. Use the following HTML.

    1 &frac12;
    Result is 1 ½

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

    Check out the following:

    span.frac {
      display: inline-block;
      text-align: center;
      vertical-align: middle;
    }
    span.frac > sup, span.frac > sub {
      display: block;
      font: inherit;
      padding: 0 0.3em;
    }
    span.frac > sup {border-bottom: 0.08em solid;}
    span.frac > span {display: none;}
    <p>7&nbsp;<span class="frac"><sup>42</sup><span>&frasl;</span><sub>73</sub></span>.</p>

    CodePen

    0 讨论(0)
提交回复
热议问题