此知識點是在做APP是所用的,項目所用技術(ionic5/angular8),僅供參考!
getRem(pWidth): void {
const htmlRoot = document.getElementsByTagName('html')[0];
const oWidth = document.body.clientWidth || document.documentElement.clientWidth;
htmlRoot.style.fontSize = oWidth / pWidth * 100 + 'px';
}
pWidth:代表設計稿的寬度
100px=1rem