我有三个 div
元素:一个作为页头,一个作为页脚,以及一个中心内容的 div
。
中心的 div
需要根据内容自动扩展,但我想设置一个 min-height
,以使底部的 div
至少达到窗口底部,但在较长的页面上不固定在那里。
例如:
<div id="a" style="height: 200px;">
<p>This div should always remain at the top of the page content and should scroll with it.</p>
</div>
<div id="b">
<p>This is the div in question. On longer pages, this div needs to behave normally (i.e. expand to fit the content and scroll with the entire page). On shorter pages, this div needs to expand beyond its content to a height such that div c will reach the bottom of the viewport, regardless of monitor resolution or window size.
</div>
<div id="c" style="height: 100px;">
<p>This div needs to remain at the bottom of the page's content, and scroll with it on longer pages, but on shorter pages, needs to reach the bottom of the browser window, regardless of monitor resolution or window size.</p>
</div>
padding-bottom: 50px
,因为我的页脚高度为50像素。 - SyntaxRulesheight: auto !important; /* real browsers */; min-height: 100%;
真的很好用!谢谢。 - Jeaf Gilbert