I have a fraction and I want to display it neatly and nicely.
For example
4/5
would be
4
—
5
I have looked at this and while this solution is decent the problem lies in having the 4 and the 5 in the same line with a straight line separating them as in traditional fractions.
Any hack or solution would be acceptable. Not necessarily CSS, Javascript or any other language is acceptable.
Fractions don't exist in JavaScript, but you can rewrite them as division problems using the division operator. Note that the resulting number is always converted to decimals — just like with a calculator. Improper fractions use the division operator in the same way.
If you want to make this navigational unordered list horizontal, you have basically two options: Make the list items inline instead of the default block. .li { display: inline; } This will not force breaks after the list items and they will line up horizontally as far as they are able.
Yes, you can specify fractional pixels. As this has been part of CSS since the very first version, it should be well supported by any browser that supports CSS at all.
The HTML5 MathML <mfrac> tag is an inbuilt element in HTML5. It is use to add fraction symbol between two digits or equations.
Use this
<sup>6</sup>/<sub>7</sub>
DEMO
For straight line
HTML
<div class="top">2</div><div class="bottom">6</div>
CSS
.top{border-bottom:solid black 1px; display:inline-block; float:left} .bottom{ display:inline-block; clear:left; float:left}
DEMO 2
.fraction {
display: inline-block;
position: relative;
vertical-align: middle;
letter-spacing: 0.001em;
text-align: center;
font-size: 12px;
}
.fraction > span {
display: block;
padding: 0.1em;
}
.fraction span.fdn {border-top: thin solid black;}
.fraction span.bar {display: none;}
Foobar
<div class="fraction">
<span class="fup">4</span>
<span class="bar">/</span>
<span class="fdn">5</span>
</div>
Foobar
Change .fraction font-size to get it to a size you want
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With