本文介绍了CSS字体rem技巧:62.5%或6.25%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在REM和Internet上使用字体大小调整,我在技巧:

I would like to use font sizing with REM and on internet I found following trick:

html { font-size: 62.5%; }
body { font-size: 1.4rem; } /* =14px */
h1   { font-size: 2.4rem; } /* =24px */

由于设置font-size: 62.5%;覆盖率rem <-> px(像素)非常容易(只需将像素值除以10)即可.

due to set font-size: 62.5%; coversion rem <-> px (pixels) is very easy (just divide pixel value by 10).

但是我想知道-为什么不使用值 6.25%-在这种情况下,我们的诀窍将如下所示:

However I wonder - why not use value 6.25% - in that case our trick will be look like this:

html { font-size: 6.25%; }
body { font-size: 14rem; } /* =14px */
h1   { font-size: 24rem; } /* =24px */

这种方法看起来更直接,因为它的价值为62.5%(我们可以将rem转换为px而无需更改数字值)-但是我有一个问题-为什么上网"的人不使用这种方法-可能会导致某些问题问题(我不知道)?

and this approach look to be more direct that for value 62.5% (we can convert rem to px without changing number value) - however I have question - why people "on internet" not use this approach - may be it cause some problems (that I'm not aware)?

推荐答案

62.5%的16px是10px,这是一个更合理的基本字体大小,可以作为不支持rem单元的较旧浏览器的后备,例如IE8,Firefox 3.5,Safari 4和Opera11.如果设置font-size: 6.25%,则不了解rems的旧版浏览器将忽略所有rem声明,并以很小的字体显示整个站点,从而使其不可读.请记住,16像素(尽管有用户定义的字体大小)的6.25%是 1像素.

62.5% of 16px is 10px, a much more reasonable base font size that can serve as a fallback for older browsers that don't support the rem unit such as IE8, Firefox 3.5, Safari 4 and Opera 11. If you set font-size: 6.25%, older browsers that don't understand rems will ignore all your rem declarations and see your entire site in the same very small print, making it unreadable. Keep in mind that 6.25% of 16px (user-defined font sizes notwithstanding) is one pixel.

传统方法没有什么问题,以您的方式偏离它没有任何好处-只有陷阱.是的,您可以说您不支持较旧的浏览器,这很好,但这并不能改变以下事实:使用较旧的浏览器在您的网站上发生访问的人将获得无法理解的体验传统方法只是因为您(您的作者)想要在样式表中进行1:1 px到rem的映射.

There has been nothing wrong with the traditional approach and there are no benefits to deviating from it the way you have — only pitfalls. Yes, you can say that you're not supporting older browsers, and that's fine, but that doesn't change the fact that someone who happens across your site in an older browser is going to get an unreadable experience that wouldn't happen with the traditional approach just because you, the author, wanted 1:1 px-to-rem mappings in your stylesheet.

这篇关于CSS字体rem技巧:62.5%或6.25%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 13:55