当前位置:网站首页>Avoid using 100vh[easy to understand] at mobile terminal
Avoid using 100vh[easy to understand] at mobile terminal
2022-06-27 22:48:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
CSS The viewport units in sound great . If you want to style elements to occupy the height of the entire screen , You can set height: 100vh, You have a perfect full screen element , The element resizes as the viewport changes ! It is sad , This is not the case .100vh stay Move Browsers are broken in subtle but basic ways , This makes it almost useless . It's best to avoid 100vh , It depends on javascript Set the height for a full viewport experience .
The core issue is mobile browsers ( I'm browsing for you ,Chrome and Safari) have “ help ” function , The address bar is sometimes visible , Sometimes hidden , This changes the visible size of the viewport . These browsers will not 100vh Adjust the height to the visible part of the screen when the viewport height changes , It's going to be 100vh Set to the height of the browser , And hide the address bar . The result is , When the address bar is visible , The bottom of the screen will be cut off .
As shown below :
When the address bar is displayed , Because the mobile browser mistakenly put 100vh Set to screen height without displaying the address bar , So the bottom of the screen is cut off . In the diagram above , Buttons that should be hidden at the bottom of the screen . What's worse is , When a user visits a website on a mobile device for the first time , The address bar will be visible at the top , So the default experience is a broken experience .
Better solution :window.innerHeight
One way to solve this problem is to rely on javascript instead of CSS. When the page loads , Set the height to window.innerHeight The height can be correctly set to the visible part of the window . If the address bar is visible , be window.innerHeight Will be full screen height . If the address bar is hidden , be window.innerHeight Will be the height of the visible part of the screen , This is exactly what you expect .
stay Wordsheet.io At school , You can see this . for example , Try opening on your mobile browser wordsheet.io/demo/V3Y . Whether the address bar is visible or not , The screen will be the height of the viewport . Besides , By locking the height in place when the page is first loaded , It can prevent the address bar from being hidden in the process of using the website , This brings an embarrassing screen resizing experience .
Unfortunately , Don't rely on JavaScript Under the circumstances , There is still no easy way to make elements occupy the entire viewport height . height: 100vh Very close to , But in view of its limitations on mobile devices , It's best to avoid using it .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/133174.html Link to the original text :https://javaforall.cn
边栏推荐
- Follow the archiving tutorial to learn rnaseq analysis (III): count standardization using deseq2
- Do you know the full meaning of log4j2 configurations? Take you through all the components of log4j2
- average-population-of-each-continent
- Management system itclub (Part 1)
- Where can I set the slides on the front page of CMS applet?
- Codeforces Round #722 (Div. 2)
- MySQL greater than less than or equal to symbol representation
- The problem of minimum modification cost in two-dimensional array [conversion question + shortest path] (dijkstra+01bfs)
- 医美大刀,砍向00后
- netERR_ CONNECTION_ Refused solution
猜你喜欢

Azure Kinect DK realizes 3D reconstruction (PC non real time version)

渗透学习-靶场篇-pikachu靶场详细攻略(持续更新中-目前只更新sql注入部分)

月薪3万的狗德培训,是不是一门好生意?

Livox Lidar+海康Camera 基于loam的实时三维重建生成RGB彩色点云

九九乘法表——C语言

Do280openshift access control -- Security Policy and chapter experiment

Crawler notes (1) - urllib

这类人开始被VC疯抢,月薪8万

Educational Codeforces Round 108 (Rated for Div. 2)

使用sqlite3语句后出现省略号 ... 的解决方法
随机推荐
Which method is called for OSS upload
Mysql database experiment report (I)
宏任务、微任务理解
Structured machine learning project (II) - machine learning strategy (2)
Basics of operators
Summary of various loams (laser SLAM)
信通院举办“业务与应用安全发展论坛” 天翼云安全能力再获认可
Oracle obtains the beginning and end of the month time, and obtains the beginning and end of the previous month time
About the SQL injection of davwa, errors are reported: analysis and verification of the causes of legal mix of settlements for operation 'Union'
How to use RPA to achieve automatic customer acquisition?
netERR_ CONNECTION_ Refused solution
Memoirs of actual combat: breaking the border from webshell
Azure Kinect DK 实现三维重建 (PC非实时版)
网易云“情怀”底牌失守
Management system itclub (Part 1)
改善深层神经网络:超参数调试、正则化以及优化(三)- 超参数调试、Batch正则化和程序框架
Beijing University of Posts and Telecommunications - multi-agent deep reinforcement learning for cost and delay sensitive virtual network function placement and routing
【微服务】(十六)—— 分布式事务Seata
Consumer finance app user insight in the first quarter of 2022 - a total of 44.79 million people
个人TREE ALV 模版-加快你的开发