我一直在尝试创建一组整页 DIV,但在移动平台上没有成功。在 iOS 和 Android 设备上,第一个 DIV 会正常显示,但即使我的边距设置为“0”,第二个也会有顶部边距。
滚动到底部后,第一个 DIV 的红色仍然可见。
这是我用来复制问题的 JavaScript...
$(document).ready(function() {
$(window).resize(function() {
var newHeight = $(window).height();
$('div').css({
width: '100%',
height: newHeight + 'px'
});
});
});
CSS...
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
border: 0;
}
div {
width: 100%;
height: 100%;
}
.red {
background: red;
}
.blue {
background: blue;
}
和 HTML...
<div class="red">
</div>
<div class="blue">
</div>
最佳答案
为什么不直接使用 CSS?
.red, .blue{
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
}
关于javascript - 使用 jQuery 和 CSS 的 100% 高度 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25879651/