【发布时间】:2019-02-01 03:39:57
【问题描述】:
我想为移动设备构建响应式网站。在构建像素完美的页面时,如何控制我的高度?
您可能知道,移动浏览器不支持视口单元,这是一个已知问题。
- 我无法使用
vw或vh,因为它们不受支持 - 我不能使用
%,因为我需要为父元素设置高度 - 我不能使用
px或任何静态单位,因为我正在构建响应式设计
我整理了一些东西,以便您获得更好的主意:
* {
margin: 0;
}
#page1 {
height: 100vh;
}
#top {
height: 30%;
background: #ddd;
}
#bottom {
height: 70%;
background: #ccc;
}
#page2 {
height: 100vh;
}
#page3 {
height: 100vh;
}
<body>
<div id="page1">
<div id="top">This is the top of page1. Its height should be 30% of 100vh
</div>
<div id="bottom">This is the bottom part of page1. Its height should be 70% of 100vh</div>
</div>
<div id="page2"> This is page 2 and is also 100vh high</div>
<div id="page3"> This is page 3 and is also 100vh high</div>
</body>
现在这在 PC 上完全没问题,但在移动设备上,当地址栏隐藏/显示时它会变得跳跃,这是不可接受的。
那么vh 单元的任何替代方案?
谢谢,艾丹
【问题讨论】:
标签: html css mobile responsive-design viewport-units