webview默认字号
在有些 Android 手机上,浏览器或 webview 的默认字体是随着系统设置的字体改变的。
这样就会导致默认字体大于或小于 16px。 直接表现为:
html的font-size设置为40px 但 1rem != 40px , 1rem = 40px*(defaultFontSize / 16)
计算defaultFontSize的方法:
const d = window.document.createElement('div');
d.style.width = '1rem';
d.style.display = 'none';
const head = window.document.getElementsByTagName('head')[0];
head.appendChild(d);
const defaultFontSize = parseFloat(window.getComputedStyle(d, null).getPropertyValue('width')) || 16;
⚠️: 不止是设置系统字体会造成这个现象,有个三星手机没有设置系统字体,1rem = 17.6px,还不知道是什么导致的
部分安卓line-heigjt 垂直布局中:
.txt::before {
content: '';
display: inline-block;
vertical-align: middle;
width: 0;
height: 100%;
margin-top: 1px;
}
----------------------------
.txt {
line-height: normal
}
----------------------------
<div class="solution" style="height: 32px; line-height: 32px; font-size: 20px; transform: scale(0.5, 0.5); transform-origin: left top;">
<span>hot 热门</span>
</div>
⚠️ :有遇见过一种方案不好用,伪元素+transform+normal好用了
ios刘海屏底下的安全区域上的webview会向上蹦一下(html不贴底边)
没有找到原因,解决方案是给body一个高度 height:100vh