当前位置:网站首页>Mobile layout - fit
Mobile layout - fit
2022-07-18 11:40:00 【cc&】
1.rem adapter ( Divide the screen into 10 Share )
explain : Mobile projects need to be adapted to the screen ,rem It's a good choice
Introduce : It is css A unit of
It is a dynamic unit
It uses html Of font-size Change based on attributes
If html Of font-size The size is 37.5px, that 1em=37.5px
If html Of font-size The size is 16px, that 1em=16px
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
html{
font-size: 20px;
}
#app{
width: 10rem;
height: 20vh;
background-color: pink;
}
</style>
</head>
<body>
<!-- <script src="./flexible.js"></script> -->
<div id="app"></div>
</body>
</html>As shown in the above code #app Width =10*20=200px
Because the screen size of the mobile terminal is different , Therefore, media adaptation is needed
[email protected] screen and(max-width:400px){}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
@media screen and (min-width:414px){
html{
font-size: 41.4px;
}
}
@media screen and (max-width:375px){
html{
font-size: 37.5px;
}
}
#app{
width: 10rem;
height: 20vh;
background-color: pink;
}
</style>
</head>
<body>
<div id="app"></div>
</body>
</html>As shown in the above code , When the screen of the mobile terminal is less than or equal to 375px when ,#app Width -》10*37.5=375px
When the screen of the mobile terminal is greater than or equal to 414px when ,#app Width -》10*41.4=414px
There will be a new problem above , Now there are so many types of mobile terminals , Do you want to write one by one ,....
3. introduce flexible.js file
explain : Because there will be many screen devices in the future
It is not appropriate to add all device styles to the media query
You can use plug-ins ,flexible, To help us automatically set rem The benchmark value of
principle :flexible When the width of the screen changes :
Get the screen width
Use width Division 10 obtain rem The benchmark value of
Then set the reference value to html Of font-size attribute
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
#app{
width: 5rem;
height: 20vh;
background-color: pink;
}
</style>
</head>
<body>
<script src="./flexible.js"></script>
<div id="app"></div>
</body>
</html>Code above ,#app Take up half of the screen ( There's a little problem , Switch mobile devices ,#app You can see the change in width )
---------------------------------------------------------------------------------------------------------------------------------
Wouldn't it be better if I set the percentage of screen width ????
边栏推荐
- Getting started with redis
- thinkphp 3 增加分词权重搜索功能 phpanalysis插件
- 二叉树相关的习题讲解
- Reading a data driven graph generic model for temporary interaction networks
- Flink(五)状态编程
- flutter EventBus
- Understand the common classification of software testing
- flutter provide
- The last column of DataGridView is automatically extended to the rest
- JS array object in goods_ With the same ID and an object, put goods_ size_ Add ID values together
猜你喜欢

Emqx server establishes ssl/tls secure connection, one-way and two-way

Understand the common classification of software testing

How does the trend of banking situation in London come into being

jol-core

Flink (II) time and window

Calculate the average wage excluding the maximum wage and the minimum wage of the Department (ByteDance interview)

【MySql项目实战优化】通过执行计划分析追加索引

Flink(二)时间和窗口

2022年全国最新消防设施操作员(初级消防设施操作员)模拟试题及答案

Forco:全球首发,暴力增值,年度最佳币圈风口
随机推荐
晴空一“鹤”排“云”上:以数为翅的中国飞鹤
Vertical/Column text select in PyCharm
Torch 常用 Tricks 总结
论文阅读 A Data-Driven Graph Generative Model for Temporal Interaction Networks
Meshlab之插件式开发
jeesite登录流程
Take you to brush (niuke.com) C language hundred questions (the next day)
Database Chapter III operation
flutter 生命周期
Talking about software defect management
(manual) [sqli labs42, 43] post injection, stack injection, error echo, character injection
解密静态路由,一文分析静态路由优缺点!
Quweihai: insisting on choosing and not giving up is the magic weapon to realize the original intention
深圳开展建设工程合同网签试点,法大大助力建筑数字化
Envoy monitoring management
openpcdet之pointpillar代码阅读——第二篇:网络结构
【漫步刷题路】- 逆序字符串II
thinkphp 3 增加分词权重搜索功能 phpanalysis插件
Commencer avec redis
Some thoughts on thread switching