如果内容小于浏览器窗口的高度,我正在使用“CSS Sticky Footer”技术使页脚保持在屏幕底部,如果内容高度大于浏览器窗口的高度,它会下降到内容下方浏览器窗口的高度。
这适用于普通内容,但是我的页面内容更改而无需刷新页面。(使用 Javascript 替换 a 的内容<div>
,或将 a<div>
从更改display: none
为display: block
)。当我遇到原始页面的高度小于窗口的情况(因此页脚位于底部)并且新内容使其大于窗口时,将内容放在页脚的“后面”(而不是移动新内容下方的页脚)。
有没有办法强制浏览器“重新计算窗口大小”并使用新的页面大小呈现页面内容?
<html>
<body>
<body>
<div id="wrapper">
<div id="header"><!-- some header content here --> </div>
<div id="content" class="footer_padding"> <!-- .footer_padding gives room for the sticky footer -->
<div class="items"><!-- some normal content here which doesn't change, a list of items in my case, which when clicked, some info is displayed below -->
<a href="#" onClick="javascript:showInfoPage('longpage');">Show Item Details</a>
</div>
<div id="text">
<div class="iteminfo" id="defaultpage" style="display: block">
<!-- default content here, height smaller than window height -->
<p>Hello this is some content.</p>
</div> <!-- #defaultpage .iteminfo -->
<div class="iteminfo" id="longpage" style="display: none">
<!-- item content here, height larger than window height -->
<p>This is some long content...</p>
<p>This is some long content...</p>
<p>This is some long content...</p>
</div> <!-- #defaultpage .iteminfo -->
</div><!-- #text -->
<script language="javascript1.5" type="text/javascript">
function showInfoPage(slug)
{
jQuery('.iteminfo').css("display", "none");
jQuery('#'+slug).css("display", "block");
}
</script>
</div><!-- #content -->
</div> <!-- #wrapper -->
<div id="footer">
<!-- the sticky footer -->
<p>Hello, I am the footer, I should always be at the bottom</p>
</div>
</body>
</html>
CSS:
html
{
margin: 0px;
padding: 0px;
height: 100%;
width: 100%;
}
body
{
background-color: #ffffff;
font-size:15px;
color: #333333;
text-align:center;
width: 100%;
height: 100%;
margin: 0px;
}
div#wrapper
{
width: 100%;
min-height: 100%;
}
div#content
{
margin: 0 0 0 0;
padding: 0px;
overflow: hidden;
display: block;
position: relative;
}
.footer_padding
{
padding-bottom: 40px;
}
#footer
{
position: relative;
margin-top: -40px;
text-align: center;
width: 100%;
padding: 10px 0px 10px 0px;
background:#FFFFFF;
clear: both;
}
我创建了一个 JSFiddle,在这里显示了这个问题:http: //jsfiddle.net/7mUDa/1/