Html 如何将 <font size="10"> 转换为 px?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/819079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert <font size="10"> to px?
提问by marknt15
I need to convert <font size="10">
to px.
我需要转换<font size="10">
为px。
Example only(not correct): <font size="10">
is equivalent to 12px.
仅示例(不正确):<font size="10">
相当于 12px。
Is there any formula or table conversion out there to convert <font size="10">
to px?
是否有任何公式或表格转换可以转换<font size="10">
为 px?
回答by Eugene Yokota
<font size=1>- font size 1</font><br>
<span style="font-size:0.63em">- font size: 0.63em</span><br>
<font size=2>- font size 2</font><br>
<span style="font-size: 0.82em">- font size: 0.82em</span><br>
<font size=3>- font size 3</font><br>
<span style="font-size: 1.0em">- font size: 1.0em</span><br>
<font size=4>- font size 4</font><br>
<span style="font-size: 1.13em">- font size: 1.13em</span><br>
<font size=5>- font size 5</font><br>
<span style="font-size: 1.5em">- font size: 1.5em</span><br>
<font size=6>- font size 6</font><br>
<span style="font-size: 2em">- font size: 2em</span><br>
<font size=7>- font size 7</font><br>
<span style="font-size: 3em">- font size: 3em</span><br>
回答by Tormod Fjeldsk?r
According to The W3C:
根据W3C 的说法:
This attribute sets the size of the font. Possible values:
- An integer between 1 and 7. This sets the font to some fixed size, whose rendering depends on the user agent. Not all user agents may render all seven sizes.
- A relative increase in font size. The value "+1" means one size larger. The value "-3" means three sizes smaller. All sizes belong to the scale of 1 to 7.
此属性设置字体的大小。可能的值:
- 1 到 7 之间的整数。这将字体设置为某个固定大小,其呈现取决于用户代理。并非所有用户代理都可以渲染所有七种尺寸。
- 字体大小的相对增加。值“+1”表示大一号。值“-3”表示小三个尺寸。所有尺寸都属于 1 到 7 的范围。
Hence, the conversion you're asking for is not possible. The browser is not required to use specific sizes with specific size
attributes.
因此,您要求的转换是不可能的。浏览器不需要使用具有特定size
属性的特定尺寸。
Also note that use of the font
element is discouraged by W3 in favor of style sheets.
另请注意,font
W3 不鼓励使用该元素,而是使用样式表。
回答by Stephen Swensen
Using the data points from the accepted answer you can use polynomial interpolation to obtain a formula.
使用来自接受答案的数据点,您可以使用多项式插值来获得公式。
WolframAlpha Input: interpolating polynomial {{1,.63},{2,.82}, {3,1}, {4,1.13}, {5,1.5}, {6, 2}, {7,3}}
WolframAlpha 输入:插值多项式 {{1,.63},{2,.82}, {3,1}, {4,1.13}, {5,1.5}, {6, 2}, {7,3}}
Formula: 0.00223611x^6 - 0.0530417x^5 + 0.496319x^4 - 2.30479x^3 + 5.51644x^2 - 6.16717x + 3.14
公式:0.00223611x^6 - 0.0530417x^5 + 0.496319x^4 - 2.30479x^3 + 5.51644x^2 - 6.16717x + 3.14
And use in Groovy code:
并在 Groovy 代码中使用:
import java.math.* def convert = {x -> (0.00223611*x**6 - 0.053042*x**5 + 0.49632*x**4 - 2.30479*x**3 + 5.5164*x**2 - 6.167*x + 3.14).setScale(2, RoundingMode.HALF_UP) } (1..7).each { i -> println(convert(i)) }
回答by Steve
the font size to em mapping is only accurate if there is no font-size defined and changes when your container is set to different sizes.
字体大小到 em 映射只有在没有定义字体大小的情况下才是准确的,并且当您的容器设置为不同的大小时会发生变化。
The following works best for me but it does not account for size=7 and anything above 7 only renders as 7.
以下对我来说效果最好,但它不考虑 size=7 并且任何高于 7 的东西只呈现为 7。
font size=1 = font-size:x-small
font size=2 = font-size:small
font size=3 = font-size:medium
font size=4 = font-size:large
font size=5 = font-size:x-large
font size=6 = font-size:xx-large
回答by Lucero
In general you cannot rely on a fixed pixel size for fonts, the user may be scaling the screen and the defaults are not always the same (depends on DPI settings of the screen etc.).
通常,您不能依赖固定的字体像素大小,用户可能会缩放屏幕,并且默认值并不总是相同(取决于屏幕的 DPI 设置等)。
Maybe have a look at this(pixel to point) and this link.
But of course you can set the font size to px, so that you do know how many pixels the font actually is. This may help if you really need a fixed layout, but this practice reduces accessibility of your web site.
但是当然您可以将字体大小设置为 px,这样您就可以知道字体实际有多少像素。如果您确实需要固定布局,这可能会有所帮助,但这种做法会降低您网站的可访问性。
回答by user2845437
This is really old, but <font size="10">
would be about <p style= "font-size:55px">
这真的很旧,但<font size="10">
大约 <p style= "font-size:55px">