Explore why rem computing error on chrome, remchrome
Recently in a project, the tester raised a bug that some fonts on a page on the mobile phone are too large. Just like this
I tested it on the pc using chrome browser and found this problem on the pc, but I did not find this problem when I opened this page using other browsers.
So I went online to Baidu and found that it was a problem with the chrome browser.
Through various Baidu and Google, I summ
enlighten.So, at the moment, I think the most fundamental solution is to set the font-size size of the HTML root element to be greater than or equal to 12px.Some doubts:1, when 1rem is less than 12px, how chrome is calculated.As shown, the font-size of my HTML root element is set to 62.5% (10px), the figure of the font calculation is not 25px, but 28.5941px, this number is how to come, if the minimum 12px to calculate should be 30px is right AH.2, why some font calculation is correct, and some
selector p font size to 1.2em, but if p belongs to the content of the child, the font size of P is not 12px, but 1.2em= 1.2 * 12px=14.4px. This is because the font size of the content is set to 1.2em, the EM value inherits the size of the body of its parent element, which is 16px * 62.5% * 1.2=12px, and P as its child, EM inherits the content of the font high, that is, 12px. So the 1.2em of P is no longer 12px, but 14.4px. 3. Recalculate the EM values of the enlarged fonts. Avoid duplicate decl
Em:All browsers are compliant with: 1em=16px;1. With inheritanceThe root element of the 2.em is the body, when the size of the root element is set, the size is the defined number multiplied by the size value defined by the root elementRem:1rem=16pxREM is not inherited, its root element is HTML, when the size of the root element is set, the size is defined by the number multiplied by the size value defined by the root elementResponsive layoutResponsive layout: A Web site is compatible with multip
Em:1. font-sizeof em relative to the parent element of the Element. For example, if a 2.p { margin: 1em 0 }Indicates the paragraph left 1em blank, then the specific P element font size if it is 12px, White is also 12px, if the font is 16px, white is also 16px.Rem:REM is relative to the HTML root element, which is the HTML element, such as:html{ font-size: 14px;}p{ font-size: 2rem; /* 此时p的字体大小为28px,即html的font-size和p的*/}CSS3 relative units: em rem
Add such a section of JS, you can dynamically change the width of the screen according to the Font-sizeAccording to this sentence docEl.style.fontSize = (clientwidth/320) + ' px '; Knowiphone4 width is 320px, then Font-size is 20px, 100px is 5remIphone6 width is 375px, then Font-size is 23.4375px,100px is 4.267remMobile REM settings, auto-change html
Add such a section of JS, you can dynamically change the width of the screen according to the Font-sizeAccording to this sentence docEl.style.fontSize = (clientwidth/320) + ' px '; Knowiphone4 width is 320px, then Font-size is 20px, 100px is 5remIphone6 width is 375px, then Font-size is 23.4375px,100px is 4.267remPackage for red Rice mobile phone Xiaomi. Use media to query @media a bit of a pit. Some do not support so force the HTML to change the root dynamically according to the width of the
Gets once when the window is opened for the first timeRC ();When the window changes, get it in real time.WINDOW.ONRESIZE=RC;function RC () {Default font Sizevar fonts=20;Gets the width of the windowvar windowwidth =document.documentelement.clientwidth;Window width to obtain a scale in addition to the size of the design diagramvar rate=windowwidth/1366;Set the default size x scale for responsiveDocument.documentElement.style.fontSize = fonts*rate+ "px";}REM
1When the design is 640px, the screen under the 320px display effect is 1rem=20px; by dynamically changing the page, each element of the page can calculate the size of the element through the fontsize of the root node.Use REM for responsive layout (JS dynamic loading)
First, the user adjusts the browser font size, affects the Web page that opens from the browser.The browser sets the font size, which affects the page that the browser opens. JS can control the user to modify the font size, so that the page is not affected. (Function (doc, win) {//) the font size (ie doc.documentElement.currentStyle) {var user_webset_font=) of the browser that gets the user's settings in the native method doc.documentelement.currentstyle[' FontSize ']; } else {var user_webset_f
before doing desert education, direct to the design map, and then rape, scale processing. Simple. Straight, Rough! However, development is fast. ...... Once! But that is, now developed, as the industry conscience: can't do that! (That was forced.)First look at the code:@media screen and (max-width:362px) and (min-width:330px) {html{font-size:60%;}. top-banner{//font-size:15px//}//.btn-download{//margin-left:5%;}} @media screen and (max-width:330px) {html{font-size:53.333331%;}. top-banner{//font
1.JS loading sequence and loading methodThe page load order is usually loaded from top to bottom, so we should calculate the HTML font-size before the content area, that is, the body and the DOM contained in the body have not been traversed by the browser. We should put the computational font JS before the body, as follows:Recommended-native notation (optimized loading, faster body display):function Resize () {var htmlele = document.documentelement;var htmlwidth = window.innerwidth;HtmlEle.style
1: Nonsense not much to say, look directly like the table:
2:PX does not introduce too much, is the size of the pixel, add your screen resolution of 1920, then each of the equivalent of each has a transverse 1920 pixels;
3:em is a relative unit, generally defined in the body of the font-size as the benchmark, the default value of 1em = 16px, if we want to use "1em" = "10px" to replace the default value "1em" = "16px", should write the following code:
Body{font-size:62.5%;/*10÷16x100% = 62.5%*/}
This event is triggered when the direction of the device changes (the device is held horizontally or vertically). When this event is bound,Note that we now bind the Resize event when the browser does not support the Orientationchange event.The main thing is to listen to the changes in the window, once a change, you need to reset the root font valuevar resizeevt = ' Orientationchange ' in window ? ' orientationchange ' : ' resize ', Recalc = function() { //Set root font sizedocument.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.