重置font-size:0不能使用'em'单位 [英] Reset font-size:0 doesn't work with 'em' unit

查看:189
本文介绍了重置font-size:0不能使用'em'单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个父元素 font-size 设置为0(零)及其恢复值

I have a parent element that sets the font-size to 0 (zero) and its child that restore the value

.parent {
  font-size: 0;
}

.child {
  font-size: 1em;
  /* font-size: 16px; */
}

使用 em 它不工作。

任何人都可以解释为什么?

Can anybody explain me why?

推荐答案

是的,这是正常的。因为 em 这是一个相对的测量。如果你想想你在做什么,你就是这样:

Yes, it's normal. Because em it's a relative meassure. If you think in what are you making, you are making this:

0 * 1 = 0

因此,如果您重置为0,您将永远获得零值。

So if you reset to 0 you'll obtain forever a zero value.

您需要使用 rem (root em)或 px

You need to use rem (root em) or px.

.child {
   font-size: 1rem;
}

Rems来自文档

这篇关于重置font-size:0不能使用'em'单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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