当前位置:网站首页>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;
边栏推荐
猜你喜欢
![[301] grotesque behavior - predictable irrationality](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[301] grotesque behavior - predictable irrationality
![Public access intranet IIS website server [no public IP required]](/img/e5/45d7c59ed30bbf901f793f25e229e2.png)
Public access intranet IIS website server [no public IP required]

Jenkins自动化无人值守运行(上/下)

RESTful API介绍

Do not rent servers, build your own personal business website (3)

Heap overflow of kernel PWN basic tutorial

Jenkins automated unattended operation (up / down)

Luckyframeweb testing platform (a full latitude free open source testing platform that supports interface automation, Web UI automation, APP automation, and distributed testing)

数据集和预训练模型

Data set and pre training model
随机推荐
Homework in the second week
Do not rent servers, build your own personal business website (4)
Flink time stream processing
Do not rent servers, build your own personal business website (1)
General paging 2.0
[218] what are the advantages and disadvantages of CS architecture and BS architecture and data on the server and client?
Use of MySQL
history命令历史记录中加时间
jz47 礼物的最大价值(动态规划思路)
[award issuance] the results of the first essay solicitation activity in oneos zone were announced
IP作业(2)RIP
Login page + summary
【217】#!/ The meaning of usr/bin/env
leetcode剑指offer JZ73 翻转单词序列
grep与正则的搭配使用
API流程和代码结构
[251] common test tools
Jenkins automated unattended operation (up / down)
LuckyFrameWeb测试平台(一款支持接口自动化、WEB UI自动化、APP自动化,并且支持分布式测试的全纬度免费开源测试平台)
SSH远程访问及控制