【发布时间】:2014-09-16 22:53:46
【问题描述】:
我一直在尝试在移动平台上创建一组整页 DIV,但没有成功。在 iOS 和 Android 设备上,第一个 DIV 可以正常显示,但即使我的边距设置为“0”,第二个 DIV 也会有上边距。
滚动到底部后,第一个 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>
【问题讨论】:
-
根据 jQuery 文档,您可以使用
css('height')获得与height()相同的值,但包括单位,例如px. -
你的最终目标是什么?也许有更简单和不同的解决方案
-
在this JSFiddle中工作正常...
标签: javascript android jquery html css