当前位置:网站首页>移动适配:vw/vh
移动适配:vw/vh
2022-07-04 06:41:00 【HHppGo】
vw/vh
目标:能够使用vw单位
设置网页元素的尺寸
相对单位
相对视口的尺寸
计算结果
- vw:viewport width
– 1vw =1/100
视口宽度 - vh:viewport height
– 1vh =1/100
视口高度
代码:
<!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>体验vw和vh</title>
<style> * {
margin: 0; padding: 0; } /* 需求:分别使用vw和vh设置盒子大小 vw: 参照视口宽度计算结果,1/100 vh: 参照视口高度计算结果,1/100 */ .box {
width: 50vw; height: 30vw; background-color: pink; } /* .box { width: 50vh; height: 30vh; background-color: pink; } */ </style>
</head>
<body>
<div class="box"></div>
</body>
</html>
vw
适配原理
目标:实现在不同宽度
的设备中,网页元素尺寸等比缩放
效果
vw单位尺寸
- 确定设计稿
对应
的vw尺寸(1/100视口宽度)
– 查看设计稿宽度
-> 确定参考设备宽度
(视口宽度)-> 确定vw尺寸
(1/100视口宽度) - vw单位的尺寸 =
px单位数值 / ( 1/100 视口宽度)
vh
适配原理
vh单位尺寸
- 确定设计稿
对应
的vh尺寸(1/100视口高度)
– 查看设计稿宽度
-> 确定参考设备高度
(视口高度)-> 确定vh尺寸
(1/100视口高度) - vh单位的尺寸 =
px单位数值 / ( 1/100 视口高度)
less代码:
// out: ./ * {
margin: 0;
padding: 0;
}
// 需求:分别使用vw和vh设置 68px * 29px的盒子大小 // 设计稿是视口宽度375px,视口高度667px的 // .box {
// width: (68/3.75vw);;
// height: (29/3.75vw);;
// background-color: pink;
// }
.box {
width: (68/6.67vh);;
height: (29/6.67vh);;
background-color: green;
}
// 提示:以上二选一即可,但在工作中,通常使用vw,参照设备宽度
vw和vh的混用(不能够
)
// out: ./ * {
margin: 0;
padding: 0;
}
// 测试:vw和vh混合使用,设置68px * 29px的盒子(设计稿是 375px的) // 设计稿 375px * 667px // 提示:工作中,vw和vh不要混用,因为遇到全面屏盒子尺寸跟设计稿会不一样的 .box {
width: (68/3.75vw);
height: (29/6.67vh);
background-color: blue;
}
边栏推荐
- Mysql 45讲学习笔记(十三)表数据删掉一半,表文件大小不变
- Software keywords and process information intercepted by Golden Shield video player
- tars源码分析之7
- Distributed cap theory
- Tsinghua University product: penalty gradient norm improves generalization of deep learning model
- List of top ten professional skills required for data science work
- SQL injection SQL lab 11~22
- MySQL 45 lecture learning notes (XIII) delete half of the table data, and the table file size remains the same
- 2022, peut - être la meilleure année économique de la prochaine décennie, avez - vous obtenu votre diplôme en 2022? Comment est - ce prévu après la remise des diplômes?
- Tar source code analysis 6
猜你喜欢
Which water in the environment needs water quality monitoring
what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!
【MySQL】数据库视图的介绍、作用、创建、查看、删除和修改(附练习题)
what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!
Wechat applet scroll view component scrollable view area
C realize Snake games
[problem record] 03 connect to MySQL database prompt: 1040 too many connections
Tree DP
Common usage of time library
Deep understanding of redis -- a new type of bitmap / hyperloglgo / Geo
随机推荐
2022 wechat enterprise mailbox login entry introduction, how to open and register enterprise wechat enterprise mailbox?
[number theory] fast power (Euler power)
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
MySQL 45 lecture learning notes (XIV) count (*)
Background and current situation of domestic CDN acceleration
[backpack DP] backpack problem
Mysql 45讲学习笔记(十三)表数据删掉一半,表文件大小不变
17-18. Dependency scope and life cycle plug-ins
Arcpy uses the updatelayer function to change the symbol system of the layer
Overview of convolutional neural network structure optimization
Tar source code analysis Part 3
期末周,我裂开
2022, peut - être la meilleure année économique de la prochaine décennie, avez - vous obtenu votre diplôme en 2022? Comment est - ce prévu après la remise des diplômes?
Tar source code analysis Part 2
Summary of leetcode BFS question brushing
2022年,或许是未来10年经济最好的一年,2022年你毕业了吗?毕业后是怎么计划的?
tars源码分析之3
双色球案例
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
tars源码分析之7