当前位置:网站首页>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
边栏推荐
- Character interception triplets of data warehouse: substrb, substr, substring
- Beijing University of Posts and Telecommunications - multi-agent deep reinforcement learning for cost and delay sensitive virtual network function placement and routing
- 广告太「野」,吉野家「渡劫」
- 元气森林的5元有矿之死
- Do280openshift access control -- Security Policy and chapter experiment
- 网易云“情怀”底牌失守
- Educational Codeforces Round 108 (Rated for Div. 2)
- mysql操作入门(四)-----数据排序(升序、降序、多字段排序)
- Azure Kinect DK realizes 3D reconstruction (PC non real time version)
- ABAP essay-excel-3-batch import (breaking through 9999 lines of standard functions)
猜你喜欢

资深猎头团队管理者:面试3000顾问,总结组织出8大共性(茅生)

STM32与RC522简单公交卡系统的设计

改善深层神经网络:超参数调试、正则化以及优化(三)- 超参数调试、Batch正则化和程序框架

雪糕还是雪“高”?
扁平数组和JSON树的转换

Infiltration learning - problems encountered during SQL injection - explanation of sort=left (version(), 1) - understanding of order by followed by string

Deep learning has a new pit! The University of Sydney proposed a new cross modal task, using text to guide image matting

结构化机器学习项目(一)- 机器学习策略

Summary of various loams (laser SLAM)

對話喬心昱:用戶是魏牌的產品經理,零焦慮定義豪華
随机推荐
Gartner focuses on low code development in China how UNIPRO practices "differentiation"
Solution to the error of VMware tool plug-in installed in Windows 8.1 system
九九乘法表——C语言
渗透学习-sql注入过程中遇到的问题-针对sort=left(version(),1)的解释-对order by后接字符串的理解
The karsonzhang/fastadmin addons provided by the system reports an error
Basic knowledge of loop traversal and function
使用sqlite3语句后出现省略号 ... 的解决方法
Workflow automation low code is the key
[cloud based co creation] what is informatization? What is digitalization? What are the connections and differences between the two?
About the SQL injection of davwa, errors are reported: analysis and verification of the causes of legal mix of settlements for operation 'Union'
Codeforces Round #721 (Div. 2)
Service gateway of microservices
How to participate in openharmony code contribution
最虚的华人首富更虚了
爬虫笔记(2)- 解析
Dialogue with Qiao Xinyu: the user is the product manager of Wei brand, and zero anxiety defines luxury
Macro task and micro task understanding
Re recognize G1 garbage collector through G1 GC log
Start the start php
OData - SAP S4 OP 中使用SAP API Hub 的API