How can I write a complex fraction using HTML/CSS/jQuery?

ぐ巨炮叔叔 提交于 2019-12-05 21:34:46

Alright, I found a better way to do what you were doing. No extra CSS, just some tabular magic.

<table><tr><td>
<div style="float:left;">Substitute 4 for 'x' in the equation: &nbsp;</div></td>
 <td> <div style="float:left">
    <div style="border-bottom:1px solid;font-size:small;text-align:center;">x<sup>2</sup> + 3x + 5</div>
    <div style="font-size:small;text-align:center;">2x</div>
  </div></td>
</tr>
</table>

Tables auto-center-align :D

For more text, add more <td>s. Keep text-<td>s and math-<td>s separate. Add another <tr> for a new line.

<table><tr><td>
<div style="float:left;">Substitute 4 for 'x' in the equation: &nbsp;</div></td>
 <td> <div style="float:left">
    <div style="border-bottom:1px solid;font-size:small;text-align:center;">x<sup>2</sup> + 3x + 5</div>
    <div style="font-size:small;text-align:center;">2x</div>
  </div></td>
<td>. If you feel bored, solve this as well:</td>
<td> <div style="float:left">
    <div style="border-bottom:1px solid;font-size:small;text-align:center;">y<sup>2</sup> + 3x+5y<sup>5</sup> + 5</div>
    <div style="font-size:small;text-align:center;">1000</div>
  </div></td>
</tr>
<tr>
<td>
<div style="float:left;">Substitute 4 for 'x' in the equation: &nbsp;</div></td>
 <td> <div style="float:left">
    <div style="border-bottom:1px solid;font-size:small;text-align:center;">x<sup>2</sup> + 3x + 5</div>
    <div style="font-size:small;text-align:center;">2x</div>
  </div></td>
<td>. If you feel bored, solve this as well:</td>
<td> <div style="float:left">
    <div style="border-bottom:1px solid;font-size:small;text-align:center;">y<sup>2</sup> + 3x+5y<sup>5</sup> + 5</div>
    <div style="font-size:small;text-align:center;">1000</div>
  </div></td>
</tr>
</table>
ilivewithian

This is what LaTeX is for. Here's a jQuery plugin which seems to have a nice implementation: http://blog.dreasgrech.com/2009/12/jslatex-jquery-plugin-to-directly-embed.html

Manishearth

I would personally suggest MathJax. (it uses HTmL/CSS)

But, if you do not want to resort to a TeX renderer, then you may want to investigate the CSS behind a MathJax fraction with Chrome Inspector.

Go to this answer of mine, Ctrl-Shift-I (in Chrome), use the inspector magnifying glass on the fraction. Then check out the CSS in the sidepane.

I've made a quick jsfiddle

I'm not sure quite what you mean when you said that divs and borders made it look awful, becuase my solution is quite similar.

It just uses spans and borders.

It's not perfect: the text does not get aligned to the center, but it's a nice quick alternative to a TeX renderer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!