【发布时间】:2014-08-03 17:54:33
【问题描述】:
我有以下代码:
CSS
#container{
font-size: 0.625em;
}
#div1 {
width: 200px;
height: 200px;
background-color: green;
}
#div2 {
width: 20em;
height: 20em;
background-color: red;
}
HTML
<div id="container">
<div id="div1">
This is a test message.This is a test message.This is a test message.This is a test message.
</div>
<div id="div2">
This is a test message.This is a test message.This is a test message.This is a test message.
</div>
</div>
Chrome 版
Version 35.0.1916.153 m
当您在 Chrome 中缩放到 50% 或更小时,两个 div 的大小会变得不同。 如果您在开发工具中检查字体大小,您会意识到 Chrome 会自动增加文档的字体大小。
谁能告诉我为什么会这样? 我该如何预防呢?
我正在研究em和px的区别,所以把#div2的宽度改成200px是不行的。
更新了内容和来源。
感谢您的帮助。
2014 年 6 月 16 日更新
发现了一些有趣的东西,想在这里与大家分享。
如果您曾经在 Chrome 中触摸过“高级字体设置”,或者使用默认版本(不是中文或日文):
您永远不能将字体大小设置为小于 6px 的数字(中文或日文版本为 12px)。
当您用“em”测量“高度”之类的东西时,1em 永远不会小于 6px(12px)。
如果您将文本设置为 6 像素,并缩放至 50%,您可能会看到文本呈现为 3 像素(变为一半)。但是文本会被 chrome 设置为 12px,并且可能会破坏您的布局。
感谢达瓦尔·侯赛因。他帮我实现了最小字体大小的事情。
【问题讨论】:
标签: css google-chrome