在CSS的font-size属性中使用分数em [英] Using fractional em's in CSS's font-size property

查看:264
本文介绍了在CSS的font-size属性中使用分数em的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说,我定义了以下CSS规则:

Say, I have the following CSS rule defined:

.className {
font-size:0.89em;
}

我的问题是, em对于浏览器实际上支持它,并且对于em的值中的小的分数变化,字体大小被不同地渲染。

My question is, how "deep" into fractions can I go while specifying 'em's for browsers actually to support it and for the font size to be rendered differently for a small fractional change in the em's value?

推荐答案

JohnB是对的。我们仍然以像素为单位渲染像素,无论我们使用的尺寸单位,ems中的小改变不会改变显示的大小:

JohnB is right. We're still rendering in pixels whatever the size unit we use, and small changes in ems will not change the displayed size:

例如,对于最初显示在高度为20px *,我们可以看到,当添加规则以使其成为它的原始高度的.99em时,没有有效的改变:

For example, for text originally displaying at a height of 20px*, we can see that there is no effective change when a rule is added to make it .99em of its original height:

20 * 0.99 = 19.8 

浏览器无法显示.8的像素,因此

The browser can't display .8 of a pixel, so (assuming it will round up) it will still display it as 20px high.

虽然看起来浏览器并不总是如预期那样四舍五入:

Though it appears that browsers do not always round off as expected:

http://meyerweb.com/eric/thoughts/ 2010/02/10 / rounding-off /

http://ejohn.org/blog/sub-pixel-problems-in-css/

*是的,我知道20px的font-size并不总是意味着它以20px显示!

*Yep, I know a font-size of 20px doesn't alway mean it's displayed at 20px!

这篇关于在CSS的font-size属性中使用分数em的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆