


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!

In this post, Blackle Mori shows you a few of the hacks found while trying to push the limits of Cohost’s HTML support. Use these if you dare, lest you too get labelled a CSS criminal.

Custom cursors with CSS are great, but we can take things to the next level with JavaScript. Using JavaScript, we can transition between cursor states, place dynamic text within the cursor, apply complex animations, and apply filters.

Interactive CSS animations with elements ricocheting off each other seem more plausible in 2025. While it’s unnecessary to implement Pong in CSS, the increasing flexibility and power of CSS reinforce Lee's suspicion that one day it will be a

Tips and tricks on utilizing the CSS backdrop-filter property to style user interfaces. You’ll learn how to layer backdrop filters among multiple elements, and integrate them with other CSS graphical effects to create elaborate designs.

Well, it turns out that SVG's built-in animation features were never deprecated as planned. Sure, CSS and JavaScript are more than capable of carrying the load, but it's good to know that SMIL is not dead in the water as previously

Yay, let's jump for text-wrap: pretty landing in Safari Technology Preview! But beware that it's different from how it works in Chromium browsers.

This CSS-Tricks update highlights significant progress in the Almanac, recent podcast appearances, a new CSS counters guide, and the addition of several new authors contributing valuable content.

Most of the time, people showcase Tailwind's @apply feature with one of Tailwind's single-property utilities (which changes a single CSS declaration). When showcased this way, @apply doesn't sound promising at all. So obvio


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

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
