问题描述:如果不设置viewport,会导致移动端中较长的文字字体变化
简单来说,我现在有这样一段代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<div>This is not so long a piece of text.</div>
</body>
</html>
然后我在chrome的手机模拟器里打开这个网页,一切正常。但是,如果我把内容换成下面这样(增加div内容长度):
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<div>This is a very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long piece of text.</div>
</body>
</html>
此时,手机模拟器中的字体变得很大,用getComputedStyle
获取字体发现字体变成了41.791px。
这个问题倒是很好解决,只要加上viewport meta标签就行,但是我没明白为什么同一个设备、同一个浏览器,只是内容长度不同,就会导致渲染出的字体大小不同?
录制了一段视频,如下:
[https://www.veed.io/view/a26252b7-1a3c-4ada-8b82-cbbc1e677621...]
这是个 Feature,叫 Font Boosting。
这就是为啥很多 CSS Reset 里都会有类似这么一句:
就是为了关闭这个特性。
你也可以试试在不设置 viewport 的前提下加这么个 style 看看效果。