Summary of CSS units (such as rem, px, em, vw, vh, vm)
This article brings you a summary of CSS units (such as rem, px, em, vw, vh, vm) and introduces the differences between these units. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
px: pixel (pixel) relative length unit, relative to the screen display resolution;
em: em The value is not fixed and will be integrated with the font size of the parent element;
Note:
1. Select body and declare Font-size=62.5%;
2. Divide the original px value by 10, and then replace it with em as the unit;
3. Recalculate the em value of the enlarged fonts. Avoid repeated declarations of font sizes.
The default font size of any browser is 16px. All unadjusted browsers comply with 1em=16px, 0.75em=12px, and 10px=0.625em. In order to simplify the conversion of Font-size, you need to declare Font-size=62.5% in the body selector in CSS, which makes the value of em become 16px*62.5%=10px, so 12px is 1.2em and 10px is 1em. That is, just divide the original px value by 10 and replace it with the unit of em.
rem: Relative unit, (root em is rem). When using rem as the unit to set the font size, it is relative to the size of the HTML root element, which can be proportional to the root element. Modify and adjust all font sizes. Generally, they are written on the body or html. For example:
body{font-size:625%;}
, which is 1rem=100px;
, but it is best to match it when writing projects. Media queries together, for example:
html{font-size:10px} //10px==62.5% @media screen and (min-width:321px) and (max-width:375px){html{font-size:11px}} @media screen and (min-width:376px) and (max-width:414px){html{font-size:12px}} @media screen and (min-width:415px) and (max-width:639px){html{font-size:15px}} @media screen and (min-width:640px) and (max-width:719px){html{font-size:20px}} @media screen and (min-width:720px) and (max-width:749px){html{font-size:22.5px}} @media screen and (min-width:750px) and (max-width:799px){html{font-size:23.5px}} @media screen and (min-width:800px){html{font-size:25px}}
vw: The maximum width of the viewport, 1vw=one percent of the viewport width;
vh: The maximum height of the viewport, 1vh = one percent of the viewport height;
vmin/vm: The smaller of the width or height relative to the viewport. The smallest one is divided into 100 units of vmin (i.e. vm).
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study. For more related tutorials, please visit CSS Video Tutorial!
Related recommendations:
php public welfare training video tutorial
The above is the detailed content of Summary of CSS units (such as rem, px, em, vw, vh, vm). 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

AI Hentai Generator
Generate AI Hentai for free.

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

What coin is REMME? REMME is a cryptocurrency based on blockchain technology dedicated to providing highly secure and decentralized network security and identity verification solutions. The project aims to use distributed encryption technology to enhance and simplify the user authentication process, thereby improving security and efficiency. The innovation of REMME is that it uses the immutability and transparency of the blockchain to provide users with a more reliable identity verification method. By storing authentication information on the blockchain, REMME eliminates the single point of failure of centralized authentication systems and reduces the risk of data theft or tampering. This blockchain-based authentication method is not only more secure and reliable, but also provides users with the background of REMME. In the current digital era, the network

Because the win11 system is only a preview version and is not very stable, you can try to install it on a vm virtual machine. However, some friends don’t know whether win11 can be installed on a vm. In fact, it can be installed, and it is very simple to operate. Let’s take a look at the installation method below. Can win11 be installed on a vm? Answer: Win11 can be installed on a vm. 1. First of all, if we don’t have a vm, we can download a vm virtual machine from this site. 2. If we want to install win11 on the vm, we need to use the win11 image file, so we need to download a win11 image file to prepare. 3. After the download is completed, we first install the vm virtual machine, then open it and select "Create my virtual machine" 4.

From px to rem: The evolution and application of CSS layout units Introduction: In front-end development, we often need to use CSS to implement page layout. Over the past few years, CSS layout units have evolved and developed. Initially we used pixels (px) as the unit to set the size and position of elements. However, with the rise of responsive design and the popularity of mobile devices, pixel units have gradually exposed some problems. In order to solve these problems, the new unit rem came into being and was gradually widely used in CSS layout. one

How to use CSSViewport unit vh to create a web page layout adapted to mobile phone screens. The popularity and use of mobile phone devices is becoming more and more widespread, and more and more web pages need to be adapted to mobile phone screens. To solve this problem, CSS3 introduced a new unit - the Viewport unit, which includes vh (viewportheight). In this article, we will explore how to use vh units to create web page layouts that adapt to mobile screens, and provide specific code examples. one

vh is a relative length unit in CSS, representing a percentage of the viewport height. 1vh is equal to 1% of the viewport height. The viewport height refers to the height of the visible part of the browser window, excluding the browser toolbar, address bar and Non-page parts such as scroll bars.

Tips for creating media queries using CSSViewport units vh and vmin With the popularity of mobile devices, responsive design has become an essential technology for modern web design. To adapt to different screen sizes, developers need to adjust layout and styles through media queries. In media queries, the most commonly used unit is pixels (px). However, CSS3 introduces a new window unit, vh and vmin, which can better adapt to different device sizes. This article will introduce how to use vh and v

CSS unit attribute optimization tips: em, rem, px and vw/vh Introduction: In web design and development, CSS unit attributes play a very important role. The correct selection and use of appropriate unit attributes can make the page display more beautiful and consistent on different devices and screen sizes. This article will introduce some commonly used CSS unit properties and provide specific code examples to help readers better master these optimization techniques. em unit: em unit is calculated relative to the font size of the parent element. For example

Em in CSS is a relative length unit, which is calculated relative to the font size of the element. 1em is equal to the font size of the current element. If applied to the font size, 1em will be equal to the font size of the parent element.
