当前位置:网站首页>rem与px与em异同点
rem与px与em异同点
2022-07-29 05:10:00 【Try your best】
在css中单位长度用的最多的是px、em、rem,这三个的区别是:
一、px是固定的像素,一旦设置了就无法因为适应页面大小而改变。
二、em和rem相对于px更具有灵活性,他们是相对长度单位,意思是长度不是定死了的,更适用于响应式布局。
三、em是相对于其父元素来设置字体大小的,一般都是以的“font-size”为基准。这样就会存在一个问题,进行任何元素设置,都有可能需要知道他父元素的大小。而rem是相对于根元素,这样就意味着,我们只需要在根元素确定一个参考值。
em相对于父元素,rem相对于根元素。
1. em
(1)子元素字体大小的em是相对于父元素字体大小
(2)元素的width/height/padding/margin用em的话是相对于该元素的font-size
2.rem
rem是全部的长度都相对于根元素,根元素是谁呢?元素。通常做法是给html元素设置一个字体大小,然后其他元素的长度单位就为rem。
边栏推荐
猜你喜欢

Complete ecological map of R & D Efficiency & selection of Devops tools

Container security open source detection tool - veinmind (mirror backdoor, malicious samples, sensitive information, weak password, etc.)

Alibaba cloud and Dingjie software released the cloud digital factory solution to realize the localized deployment of cloud MES system

Day 2

ClickHouse学习(九)clickhouse整合mysql

【C语言系列】—三种方法模拟实现strlen库函数的方法

·来一篇编程之路的自我介绍吧·
![[event preview] cloud digital factory and digital transformation and innovation forum for small and medium-sized enterprises](/img/6f/f7c5d605ea9b7b9e7c49ac716492ef.jpg)
[event preview] cloud digital factory and digital transformation and innovation forum for small and medium-sized enterprises

On Paradigm

Occt learning 002 - environment construction
随机推荐
【剑指offer】— 详解库函数atoi以及模拟实现atoi函数
Side effects and sequence points
C语言文件操作
Playwright实战案例之爬取js加密数据
167. 两数之和 II - 输入有序数组
ClickHouse学习(二)ClickHouse单机安装
Day 5
Clickhouse learning (VI) grammar optimization
ClickHouse学习(五)集群操作
第一周总结
ClickHouse学习(四)SQL操作
Global components component registration
365 day challenge leetcode 1000 questions - day 037 elements and the maximum side length of squares less than or equal to the threshold + the number of subsequences that meet the conditions
个人学习笔记
paddle.fluild常量计算报错‘NoneType‘ object has no attribute ‘get_fetch_list‘
递归的基本原理
【C语言系列】— 把同学弄糊涂的 “常量” 与 “变量”
携手数字人、数字空间、XR平台,阿里云与伙伴共同建设“新视界”
存储类别
D3d Shader Instruction