[英]100% Height Not Working On Browser Resizing
I'm building an alternative to fullPage.js which will fit my needs better, but I'm having some issues getting the sections to stay at 100% height when the browser is being resized. 我正在构建fullPage.js的替代方案,它可以更好地满足我的需求,但是在调整浏览器大小时,使节保持在100%的高度时遇到了一些问题。
I have 5 sections that should all be height: 100%, width: 100%
at all times. 我有5个部分,始终都是
height: 100%, width: 100%
。 You should only be able to get one section in your browser viewport at a time. 您一次只能在浏览器视口中获得一个部分。 I did this using anchors attached to each section
id
. 我使用附加到每个部分
id
锚点来完成此操作。 Then the body
has overflow: hidden
to prevent vertical scrolling. 然后
body
出现overflow: hidden
以防止垂直滚动。 The sections each contain images that should also take up height: 100%
with the width
being determined automatically to keep aspect ration of images. 每个部分包含的图像也应占用
height: 100%
, width
是自动确定的,以保持图像的纵横比。
This solution works when I first load the page, but as soon as the browser starts being resized, other sections become visible, and the img
's that have a height: 100%
become much smaller than the full browser height. 这种解决方案在我第一次加载页面时有效,但是一旦浏览器开始调整大小,其他部分就会变得可见,并且
height: 100%
为img
变得比整个浏览器高度小height: 100%
。 Is this is a limitation to CSS, or am I doing something wrong? 这是对CSS的限制,还是我做错了什么?
Is there a javascript solution to detect browsers viewport, and apply those height
and width
values to a series of id
'? 是否有JavaScript解决方案可检测浏览器的视口,并将这些
height
和width
值应用于一系列id
'?
add this to your HEAD
section 将此添加到您的
HEAD
部分
<meta name="viewport" content="width=device-width, initial-scale=1">
then in your CSS: 然后在您的CSS中:
html, body{
height:100%;
}
@-ms-viewport{
width: device-width;
}
Additionally, I'd suggest to use vh (viewport height) and vw (viewport width). 另外,我建议使用vh(视口高度)和vw(视口宽度)。 Read more here
在这里阅读更多
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.