Builder supports REM adaptation via output.convertToRem, which can dynamically adjusts the font size according to the screen size, so that the page will be displayed correctly on different screen sizes.
By setting output.convertToRem
, the Builder can do the following things:
By default, rootFontSize is 50. So the CSS styles value are converted according to the ratio of 1rem : 50px
.
By default, builder converts all CSS properties from px to rem. If you want to convert only the font-size
property, you can setting pxtorem.propList is ['font-size']
.
The formula for calculating the font size of the page root element is:
In a mobile browser with a screen width of 390, the default value for rootFontSize is 50 and the screenWidth of the UI design is 375.
The calculated font size for the root element of the page is 52 (390 * 50 / 375
).
At this point, 1 rem is 52px, 32px (0.64 rem) in the CSS style, the actual size in page is 33.28 px.
In the desktop browser, the page rootFontSize obtained from the calculation formula is often too large. When the calculated result large than the maxRootFontSize, the maxRootFontSize will used as the page rootFontSize.
In the desktop browser with a screen width of 1920, the calculated rootFontSize is 349, which exceeds the default maxRootFontSize of 64. 64 is used as the current root element font value.
.css
file to see if the value of the corresponding property is converted from px to rem.document.documentElement.style.fontSize
.The actual rootFontSize in effect for the page is calculated dynamically based on the current page. It can be seen by printing document.documentElement.style.fontSize
or obtained by window.ROOT_FONT_SIZE
.