首页 > 解决方案 > 子节点是否从 :root 继承字体大小?

问题描述

如果我将font-sizefor 所有内容重置为零,以消除所有意外的空白,然后使用:root伪类将 font-size 设置为12pt,则子元素的htmlfont-size 仍然为零并且需要具有它们的 font-size 属性直接指定。为什么?子节点不继承root的字体大小吗?

* {
  font-size: 0;
}
:root {
  font-size: 12pt;
  font-family: sans-serif;
  color: silver;
}
 <h1>My Heading</h1>
  

* {
  font-size: 0;
}
:root {
  font-size: 12pt;
  font-family: sans-serif;
  color: silver;
}
h1 {
  font-size: 1.8rem;
}
 <h1>My Heading</h1>
  

标签: htmlcss

解决方案


推荐阅读