当前位置:网站首页>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;
边栏推荐
- leetcode剑指offer JZ42 连续子数组的最大和
- [226] instructions for Wireshark parameters
- 微信TBS在线安装内核失败的解决方法
- Do not rent servers, build your own personal business website (4)
- go的环境搭建和起步
- Leetcode sword finger offer jz42 maximum sum of continuous subarrays
- IP notes (8)
- 手动安装Apache
- [no need for public IP] configure a fixed public TCP port address for remote desktop raspberry pie
- Quickly and simply set up FTP server, and achieve public network access through intranet [no need for public IP]
猜你喜欢

leetcode剑指offer JZ23:链表中环的入口节点

IP notes (8)

MySQL从基础到入门到高可用

jz47 礼物的最大价值(动态规划思路)

Login page + summary

Data set and pre training model

IP course (OSPF) comprehensive experiment

【214】什么是自动化框架

Remember to get the password of college student account once, from scratch

Do not rent servers, build your own personal business website (1)
随机推荐
Crud of MySQL
XML parsing
Dameng database_ Dmfldr tool instructions
leetcode剑指offer JZ23:链表中环的入口节点
IP course (OSPF) comprehensive experiment
Leetcode sword finger offer jz25 merges two sorted linked lists
grep与正则的搭配使用
Windows下bat脚本备份MySQL数据库
Li Kou 986. Intersection of interval lists
Do not rent servers, build your own personal business website (1)
DHCP原理与配置
Process and planned task management
Ia class summary (2)
Leetcode sword finger offer jz23: the entry node of the link in the linked list
A batch of interview questions and answers_ 20180403 latest arrangement
[no need for public IP] configure a fixed public TCP port address for remote desktop raspberry pie
【222】内存溢出及定位
一批面试题及答案_20180403最新整理
第二周作业
RESTful API介绍