You have to use media query and set it separately, otherwise the font will be ugly You can just take a look at the mobile version of the shopping site, a lot of things have been written in it
(function (psdWidth){ var r = document.documentElement; var w = r.clientWidth; r.style.fontSize = (w > 720 ? 720 : w < 320 ? 320 : w) / psdWidth * 100 + "px"; })(640);
This is what I always use. Convert on the page according to 1rem = 100px (the size in the design draft). It is best to run it before the page style sheet is loaded, otherwise the page will flash after loading the css first and then recalculating the size.
Explanation: My company's design drawing is 750, I set font-size:20px in HTML; Then I get the px size in the design draft divided by 40 plus rem to get the mobile unit
You have to use media query and set it separately, otherwise the font will be ugly
You can just take a look at the mobile version of the shopping site, a lot of things have been written in it
(function (psdWidth){
var r = document.documentElement;
var w = r.clientWidth;
r.style.fontSize = (w > 720 ? 720 : w < 320 ? 320 : w) / psdWidth * 100 + "px";
})(640);
This is what I always use.
Convert on the page according to 1rem = 100px (the size in the design draft).
It is best to run it before the page style sheet is loaded, otherwise the page will flash after loading the css first and then recalculating the size.
js:
//JS converted from px to rem
Explanation: My company's design drawing is 750, I set font-size:20px in HTML;
Then I get the px size in the design draft divided by 40 plus rem to get the mobile unit