在CSS中设置基本REM值的正确方法是什么? [英] What's the correct way to set a base REM value in CSS?

查看:342
本文介绍了在CSS中设置基本REM值的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我对此不太确定。

Sorry, I'm a little unsure of this.

我希望我的底标为16px。但是我所读到的有关rem使用百分比的所有资源,例如:

I want my base to be 16px. But all the resources I read about rem use percentages, eg:

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

如果我希望所有rem尺寸都相对于16px,请执行我只是制作 html {font-size:16px; }

If I want all my rem sizes to be relative to 16px, do I just make html { font-size: 16px; }?

为什么要使用百分比?

推荐答案

是的,没错。您需要将html 字体大小设置为 16px 作为基本字体大小,然后使用 rem ,其余的。 Rem 仅将元素的大小与 html 相关,而 em 相对于其最近的父对象。

yes that's right. You need to make your html font-size to 16px as your base font-size and then use rem with the rest. Rem sizes the element relative only to html while em sizes relatively to its nearest parent.

这篇关于在CSS中设置基本REM值的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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