CSS使HTML页脚保持在页面底部的最小高度,但不重叠页面

CSS使HTML页脚保持在页面底部的最小高度,但不重叠页面

我有以下页面(死链接):http://www.workingstorage.com/Sample.htm)它有一个页脚,我不能让它坐在页面的底部。

我想让脚

  • 当页面较短且屏幕未被填充时,请坚持到窗口底部,以及
  • 停留在文档的末尾,当有超过一个内容的屏幕(而不是重叠的内容)时,按照正常的方式向下移动。

CSS是继承下来的,让我感到困惑;我似乎无法正确地更改它,使其在内容上设置一个最小的高度,或者使页脚移到底部。


四季花海
浏览 950回答 3
3回答

繁星淼淼

一个简单的方法就是让身体100%在您的页面中,有一个min-height的100%我也是。如果你的脚的高度不改变的话,这很好。给页脚一个负的页边距-顶部:#footer {     clear: both;     position: relative;     height: 200px;     margin-top: -200px;}

MMTTMM

我已经开发了一个非常简单的方法来将页脚放在底部,但是作为最常见的方法,您将需要调整它以适应您的页脚的高度。视图演示下面的方法通过放置::after上的伪元素。body,并将其设置为精确性页脚的高度,因此它将占用与页脚完全相同的空间,因此当页脚是absolute放置在它上面,它看起来就像页脚真的占据了空间,消除了它的绝对定位的负面影响(例如,检查身体的内容)。基本通用标记html{ height:100%; }body{ min-height:100%; padding:0; margin:0; position:relative; }header{ height:50px; background:lightcyan; }footer{ background:PapayaWhip; }/* Trick: */body {&nbsp; position: relative;}body::after {&nbsp; content: '';&nbsp; display: block;&nbsp; height: 50px; /* Set same as footer's height */}footer {&nbsp; position: absolute;&nbsp; bottom: 0;&nbsp; width: 100%;&nbsp; height: 50px;}<body>&nbsp; <header>Header</header>&nbsp; <article>Content</article>&nbsp; <footer>Footer</footer></body>下面的方法允许动态页脚高度:使用挠曲箱html, body{ height:100%; margin:0; }header{ height:50px; background:lightcyan; }footer{ height:50px; background:PapayaWhip; }/* Trick */body{&nbsp;&nbsp; display:flex;&nbsp;&nbsp; flex-direction:column;&nbsp;}footer{&nbsp; margin-top:auto;&nbsp;}&nbsp;<body>&nbsp; <header>Header</header>&nbsp; <article>Content</article>&nbsp; <footer>Footer</footer></body>使用表-布局html,body { height: 100%;&nbsp; margin: 0; }header {&nbsp; height: 50px;&nbsp; background: lightcyan;}footer {&nbsp; height: 50px;&nbsp; background: PapayaWhip;}/**** Trick: ****/body {&nbsp; display: table;&nbsp; width: 100%;&nbsp;}footer {&nbsp; &nbsp;display: table-row;}<body>&nbsp; <header>Header</header>&nbsp; <article>Content</article>&nbsp; <footer>Footer</footer></body>
打开App,查看更多内容
随时随地看视频慕课网APP