本文介绍了要使用rem单位的字体大小1px的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会做一个布局,随着缩放很好地缩放(用户按ctr / cmd + [加])。为此,我需要尺寸与字体大小一起缩放。使用em单位太难了,所以我想用rem(和复制旧的ie的每个维度属性)。

I'm going after a layout that would scale nicely along with zoom (user pressing ctr/cmd + [plus]). For that I need dimensions to scale along with font-size. Using em units is too tricky, so I'm thinking of going with rem (and duplicating every dimensional property for old ie).

我最初的想法是将html元素上的font-size设置为10px,然后使用1 / 10rem作为像素替换。但是由于body上的font-size设置为px的任意值,所以html上的字体大小将专门用于rem测量。那么为什么不将它设置为1px?

My initial idea was to set font-size on html element to 10px and then use 1/10rem as a pixel replacement. But since font-size on body is set arbitrary in px, the one on html would be used exclusively for rem measurement. So why not set it to 1px?

这些优点很明显 - 容易编写重复的声明和可维护性。

The advantages are obvious - ease of writing duplicated declarations and maintainability.

至于缺点(除了形式重复声明)我不能想到任何。但也许我错过了一些东西。这种方法有什么缺陷?

As for disadvantages (apart form duplicating declarations) I can't think of any. But maybe I'm missing something. Are there any pitfalls in this approach?

推荐答案

正如你仍然需要做一些其他方式为IE, ,我没有看到任何可能的好处的方法。只使用em,即使它需要一些计算。如果你深深嵌套的元素有自己的字体大小设置,这一切都太复杂,需要简化,而不是复杂。

As you would still need to do things some other way for IE, as you say, I don’t see any possible benefit in the approach. Just use em, even if it requires some computations. If you have deeply nested elements with their own font-size settings, it’s all too complicated anyway and needs simplification, not complication.

设置字体大小:1px是非常不自然并且会使您的样式表难以阅读和维护。

Setting font-size: 1px is highly unnatural and would make your stylesheet hard to read and maintain.

这篇关于要使用rem单位的字体大小1px的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 22:13