


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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
