admin管理员组文章数量:1427749
I am displaying text from MySQL database which has a text like this "measurement of trace gases CH4, N2O and CO2 and the processes governing their production and emissions". The text gets saved through a text area. I wanted to apply superscript/subscript to CH4, N20 and CO2 using javascript/jquery when the text is displayed in the HTML Doc? Please let me know if this is possible?
I am displaying text from MySQL database which has a text like this "measurement of trace gases CH4, N2O and CO2 and the processes governing their production and emissions". The text gets saved through a text area. I wanted to apply superscript/subscript to CH4, N20 and CO2 using javascript/jquery when the text is displayed in the HTML Doc? Please let me know if this is possible?
Share Improve this question edited Apr 2, 2013 at 12:51 webdevexp asked Dec 3, 2012 at 12:26 webdevexpwebdevexp 1092 silver badges14 bronze badges2 Answers
Reset to default 4The simplest method is to process the data so that the digits are placed inside sub
markup, e.g. CH4 bees CH<sub>4</sub>
. This, however, produces typographically poor results (including uneven line spacing), so I would suggest generating CH<span class=sub>4</span>
and using the CSS rules
.sub {
vertical-align: 0;
position: relative;
top: 0.8ex;
font-size: 80%;
}
The values used can be tuned, of course, perhaps depending on font.
Other options include using subscript characters (as suggested in @TachyonVortex’s answer) and using OpenType features for subscripting with font-feature-settings
(limited browser support, limited font support).
You can use the subscript number characters in Unicode: CH₄, N₂O, CO₂.
- Unicode Character 'SUBSCRIPT FOUR' (U+2084)
- Unicode Character 'SUBSCRIPT TWO' (U+2082)
You could write a regex to match chemical formulae (eg: CH4) and reformat them using the subscript number characters (CH₄).
You have two options:
- Store the text from the
<textarea>
in the database without any reformatting. Then when you render the HTML page, add the subscript numbers, either server-side (eg: PHP) or client-side (eg: JavaScript). - Reformat the text before writing it to the database.
Once the subscript numbers have been added, you need to ensure that you're using the UTF-8 charset from that point onwards, to avoid corrupting the characters.
本文标签: Applying supersciptsubscript tag using javascriptjqueryStack Overflow
版权声明:本文标题:Applying supersciptsubscript tag using javascriptjquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745508323a2661350.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论