rem
引入 css 代码:
html {
font-size: calc(100vw / 7.5); /** 其中7.5是设计的屏幕宽度除以100得到 **/
}
body {
font-size: 0.28rem;
}
然后在各个元素中设置尺寸:
/** 元素大小是78x78 pix **/
width: 0.78rem;
height: 0.78rem;
根据 DPR 计算设计的像素值:
export const getSizeByDPR = (size: number): number => {
const docFontSize = parseFloat(
window.getComputedStyle(document.documentElement, null).getPropertyValue('font-size')
);
return (size / 100) * docFontSize;
};