当前位置:网站首页>Difference between PX and EM and REM
Difference between PX and EM and REM
2022-07-24 06:30:00 【PS notes】
Unit overview :
px: Pixel means
em: Relative to the parent font-size value
rem: be relative to html Labeled font-size value
Use rem Set the page size of mobile terminal
characteristic : Different equipment sizes , You can solve this problem by setting the percentage , Setting percentage calculation is cumbersome , So use rem To solve .
<title> </title>
</head>
<style>
*{
margin: 0px;
padding: 0px;
}
.pin{
/* Do not use pixels when using mobile terminals , Use percentage to solve , But it is often complicated to calculate , So just use it. rem.*/
width: 26.66%;
}
</style>
<body>
<img class="pin" src="images/back.png" alt="">
</body>
</html>em: Relative to the parent font-size value
<style>
/* em yes 30 In pixels , Then his children are set to 1em So that is 3 Pixels ,10em That's the parent 30em */
.em{
font-size: 30px;
}
.em-box{
width: 10em;
height: 10em;
background-color: red;
}
</style>
<body>
<div class="em">
<div class="em-box"></div>
</div>
rem: be relative to html Labeled font-size value :
Calculate the relationship :html-font-size:30px; 1rem representative 30px ; 10rem representative 300px;
<style>
html{
font-size: 30px;
}
.em-box{
width: 10em;
height: 10em;
background-color: red;
}
</style>
<body>
<div class="em">
<div class="em-box"></div>
</div>
introduce js file ,
/head>
<script src="script/fontsizeset.js" ></script>
<style>
.box{
width: 1.5rem;
height: 1.5rem;
background-color: red;
}
</style>
<body>
<div class="box">
<h1>hello</h1>
</div>
</body>
</html>Indicate the :rem Relationship with design draft :
Suppose the company designer made a 750 Pixel design , Then let's take this 750 Pixels to set , If it changes later, it becomes 650 The pixel is to set the position below , Pictured

Case study : Will design draft px convert to rem
<script src="script/fontsizeset.js" ></script>
<style>
*{
margin: 0px;
padding: 0px;
}
.contaniner{
width: 6.72rem;
margin:0 auto;
display: flex;
align-items: center;
}
.contaniner pic{
width: 2rem;
}
.contaniner .text{
margin-left: 0.26;
}
.contaniner .text h3{
font-size: 0.28rem;
}
.contaniner.text p{
font-size: 0.24rem;
}
.contaniner.btn{
border-radius: 10%;
width: 0.96rem;
}
.btn{
background-color: aqua;
}
</style>
<body>
<div class="contaniner">
<img class="pic" src="images/ffff.jpg" alt="">
<div class="text">
<h3> The front-end development </h3>
<p>2022.7.14</p>
</div>
<button class="btn"> Button </button>
</div>
</body>
</html>
adopt js file , Set according to the window width of the browser html Elemental fontsize
doEl.style.fontSize=100*(clientWidth/750)+"px"
clientWidth Is the width of the browser window :
If the browser window width is 750px, that html Of font-size by 100px
100px=1rem;
100%=750px=?rem;
The result is :7.5rem;
If the browser Window width is 375px, that html Of font-size by 50px
50px=1rem
100%=375px=?rem
The result is :7.5rem;
边栏推荐
猜你喜欢

MySQL数据库—SQL汇总(记得关注我!中国加油!)

awk的使用

MySQL from basic to entry to high availability

进程和计划任务管理
![Configure a fixed remote desktop address [intranet penetration, no need for public IP]](/img/17/4e119be86189d80b100eb000254a86.png)
Configure a fixed remote desktop address [intranet penetration, no need for public IP]
![[226] instructions for Wireshark parameters](/img/47/0d3fd221695920e02b1f690a2a21c1.png)
[226] instructions for Wireshark parameters

IP notes (9)

How to build a website full of ritual sense and publish it on the public website 2-2

Tensorflow GPU installation -- 056

IP notes (8)
随机推荐
ip作业(1)
UE4 reload system 1. basic principle of reload system
MySQL数据库—SQL汇总(记得关注我!中国加油!)
IP class notes (4)
General paging 01
一批面试题及答案_20180403最新整理
Remote connection to Qunhui NAS at home [no public IP, free intranet penetration]
JSP tag
leetcode剑指offer JZ25 合并两个排序的链表
Tensorflow GPU installation -- 056
Set up a WordPress personal blog locally and launch it through the intranet (22)
LVM and disk quota
微信TBS在线安装内核失败的解决方法
Wasm vs EVM, Boca's choice predicts the future of the public chain
Leetcode sword finger offer JZ9 dual stack implementation queue
【214】什么是自动化框架
Understanding of Flink parallelism
Process and planned task management
go语言常用命令和包管理
leetcode 不用加减乘除算加法 || 二进制中1的个数