当前位置:网站首页>移动适配: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;
}
边栏推荐
- [Android reverse] function interception (CPU cache mechanism | CPU cache mechanism causes function interception failure)
- C實現貪吃蛇小遊戲
- Abap:ooalv realizes the function of adding, deleting, modifying and checking
- tars源码分析之8
- 11. Dimitt's law
- Invalid bound statement (not found): com. example. mapper. TblUserRecordMapper. login
- Fundamentals of SQL database operation
- Distributed cap theory
- 【MySQL】数据库视图的介绍、作用、创建、查看、删除和修改(附练习题)
- Reading notes of Clickhouse principle analysis and Application Practice (4)
猜你喜欢
Overview of convolutional neural network structure optimization
Abap:ooalv realizes the function of adding, deleting, modifying and checking
uniapp 自定义环境变量
MySQL 45 lecture learning notes (VII) line lock
27-31. Dependency transitivity, principle
云原生——上云必读之SSH篇(常用于远程登录云服务器)
2022 Xinjiang's latest eight members (Safety Officer) simulated examination questions and answers
C language - Blue Bridge Cup - Snake filling
【MySQL】数据库视图的介绍、作用、创建、查看、删除和修改(附练习题)
Matlab remainder
随机推荐
leetcode825. 适龄的朋友
Distributed cap theory
【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 ~!
198. House raiding
Average two numbers
2022 is probably the best year for the economy in the next 10 years. Did you graduate in 2022? What is the plan after graduation?
测试用例的设计
24 magicaccessorimpl can access the debugging of all methods
Displaying currency in Indian numbering format
Mysql 45讲学习笔记(十二)MySQL会“抖”一下
tars源码分析之9
tars源码分析之5
Download kicad on Alibaba cloud image station
tars源码分析之6
7. Agency mode
what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!
Modify TCP timestamp to optimize transmission performance
uniapp 自定義環境變量
Realize IIC data / instruction interaction with micro batg135