search
HomeWeb Front-endCSS TutorialSummary of CSS units (such as rem, px, em, vw, vh, vm)

Summary of CSS units (such as rem, px, em, vw, vh, vm)

Oct 10, 2018 pm 04:14 PM
css unitempxremvhvmvw

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

CSS Online Manual

##div/css graphic 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!

Statement
This article is reproduced at:博客园. If there is any infringement, please contact admin@php.cn delete
A Little Reminder That Pseudo Elements are Children, Kinda.A Little Reminder That Pseudo Elements are Children, Kinda.Apr 19, 2025 am 11:39 AM

Here's a container with some child elements:

Menus with 'Dynamic Hit Areas'Menus with 'Dynamic Hit Areas'Apr 19, 2025 am 11:37 AM

Flyout menus! The second you need to implement a menu that uses a hover event to display more menu items, you're in tricky territory. For one, they should

Improving Video Accessibility with WebVTTImproving Video Accessibility with WebVTTApr 19, 2025 am 11:27 AM

"The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."- Tim Berners-Lee

Weekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteWeekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteApr 19, 2025 am 11:25 AM

In this week's roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.

Making width and flexible items play nice togetherMaking width and flexible items play nice togetherApr 19, 2025 am 11:23 AM

The short answer: flex-shrink and flex-basis are probably what you’re lookin’ for.

Position Sticky and Table HeadersPosition Sticky and Table HeadersApr 19, 2025 am 11:21 AM

You can't position: sticky; a

Weekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryWeekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryApr 19, 2025 am 11:18 AM

In this week's look around the world of web platform news, Google Search Console makes it easier to view crawled markup, we learn that custom properties

IndieWeb and WebmentionsIndieWeb and WebmentionsApr 19, 2025 am 11:16 AM

The IndieWeb is a thing! They've got a conference coming up and everything. The New Yorker is even writing about it:

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools