div 的内容将动态设置。div #background 应该适应(单独的)div 将具有的高度。当浏览器调整大小时,背景也应该适应 div 的大小调整。因此,该操作应该在页面加载或调整浏览器大小时发生。
<div id="wrapper">
<div id="background"></div>
<div id="content">
<p>This content will be set dynamically.
<br>The div #background should adapt to this height.
<br><br><br><br><br><br>
<br>This should happen when the page loads,
<br>or when the browser is resized.
<br>At this moment, it only works when
<br>the page loads.
<br>
</p>
<!-- end #content -->
</div>
<!-- end #wrapper -->
目前,它仅在页面加载时才有效,尽管我添加了以下代码:
$(window).resize(function () {
$("#background").css({
height: ($("#wrapper").height() + 50) + 'px'
});
});
我怎样才能使调整大小的位起作用?谢谢。