Reset font-size:0 doesn't work with 'em' unit

橙三吉。 提交于 2019-12-12 06:05:40

问题


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; */
}

Using em it doesn't work. Using px as unit makes the text appear again instead.

Can anybody explain me why?


回答1:


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

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

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

.child {
   font-size: 1rem;
}

Rems are from the document



来源:https://stackoverflow.com/questions/33894589/reset-font-size0-doesnt-work-with-em-unit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!