Home > Article > Web Front-end > The distinction between css font units and the implementation of font responsiveness
The following is a detailed explanation of the distinction between CSS font units and the implementation of responsive fonts. The content is quite good. I would like to share it with you now and give it as a reference.
Problem scenario:
In the process of implementing responsive layout, how to set the font size in different window sizes and different Readability of mobile devices?
What you need to know are:
1. The conversion relationship between px, em, pt
1em = 16px
1px = 1/16 em = 0.0625em
////The following are used less //////
1em = 12pt
1px = 3/4 pt = 0.75pt
1pt = 1/12 em 0.0833em
1pt = 4/3 px = 1.3333px
2. The default font of any browser is 16px. The default size of all unadjusted browsers is 1em=16px
3. Chrome forces the minimum font to be 12px. Even if it is set to 10px, it will eventually be displayed as 12px. This explains why sometimes the font size in ie or mozllia is different from that in chrome
4. What is the difference between px, em, rem vw, vh, vmin?
px:
Relative unit. Relative to screen resolution. This is why the larger the resolution, the smaller the font size. So what are the advantages and disadvantages of px?
Advantages: relatively stable and accurate.
Disadvantages: If the page is scaled, the readability of the text will be affected. This problem can be solved by using em as the font unit.
em:
Relative unit. Scaling the font size based on the base value is a relative value, not a specific value. The base value depends on the font-size set by the parent element. If the parent element does not set font-size, search upwards until the root node.
Advantages: Makes up for the shortcomings of px
Disadvantages: Too much reliance on parent nodes, prone to repeated declarations of font size.
rem:
Relative unit. The font size relative to the root node html.
Disadvantages: It avoids em's dependence on the font size of the parent element
Advantages: There is only one reference system, the font size of the root node
<SPAN style="FONT-SIZE: 16px">html{font-size:100%} //响应式的字体大小相对于根节点变化 @media (min-width: 640px) { body {font-size:1rem;} } @media (min-width:960px) { body {font-size:1.2rem;} } @media (min-width:1100px) { body {font-size:1.5rem;} } </SPAN>
5. Why does the font size of the root node need to be Set to 62.5%?
As mentioned above, the default font size of the browser is 16px. What if you want to set the font size to 12, 14, and 18px under different page sizes?
Is it necessary to use 12/16 rem, 14/16rem, 18/16rem to calculate the relative size of the font?
A simpler way is to use the root node Set the font size to 10px, so that it can be directly written as 1.2rem, 1.4rem, 1.8rem in media. If the root node is set to 10px, then the font size relative to the browser's default font size is font-size:10/16 %, that is, font-size:62.5%
<SPAN style="FONT-SIZE: 16px">html{font-size:10px} //响应式的字体大小相对于根节点变化 @media (min-width: 640px) { body {font-size:1m=1.2 rem;font-size:12px; /某些浏览器不支持rem/} } @media (min-width:960px) { body {font-size:1.4 rem; font-size:14px; /*某些浏览器不支持rem,需要再次使用px声明font-size*/} } @media (min-width:1100px) { body {font-size:1.8 rem; font-size:18px; /*同上*/} } </SPAN>
<SPAN style="FONT-SIZE: 16px">html{font-size:16px} //响应式的字体大小相对于根节点变化 @media (min-width: 640px) { body {font-size:12/16 rem;font-size:12px; /某些浏览器不支持rem,需要再次使用px 声明font-size/} } @media (min-width:960px) { body {font-size:14/16 rem; font-size:14px; /*某些浏览器不支持rem,需要再次使用px声明font-size*/} } @media (min-width:1100px) { body {font-size:18/16 rem; font-size:18px; /*同上*/} } </SPAN>
The above is the entire content of this article, I hope it will be helpful to everyone Learning is helpful. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
Code to use css to force English word line breaks
css
The mask layer implemented by div is compatible with IE6-IE9 and FireFox browsers
The above is the detailed content of The distinction between css font units and the implementation of font responsiveness. For more information, please follow other related articles on the PHP Chinese website!