我有这个html结构,这个部分基本上是我的主要内容:
<html>
<head>
<body>
  <nav id="primary">
  <nav id="secondary">
  <section id="maincontainer">
    <div id="main">...</div>
    <footer>
     <div class="footer-inner">...</div>
    </footer>
  </section>
</body>
</html>
在id 'main‘的div中,有通过ajax动态加载的内容,因此高度可能会有所不同。我需要页脚总是在底部,即使是子页面几乎没有任何内容没有填充页面高度。目前我对页脚有绝对位置,这不适用于动态内容页,页脚被卡在内容的中间(原始窗口高度位置)。
有办法只做这个css吗?谢谢!
发布于 2017-05-11 09:53:16
做这个
<footer style="position: fixed; bottom: 0; width: 100%;"> </footer>您也可以阅读flex,它是所有现代浏览器所支持的。
更新:,我读到了关于flex的文章,并试用了它。对我起作用了。希望这对你也是一样的。下面是我如何implemented.Here main不是ID,而是<main> div
body {
    margin: 0;
    display: flex;
    min-height: 100vh;
    flex-direction: column;
}
main {
    display: block;
    flex: 1 0 auto;
}在这里,您可以阅读更多关于flex https://css-tricks.com/snippets/css/a-guide-to-flexbox/的内容。
请记住,IE的旧版本不支持它。
https://stackoverflow.com/questions/43911921
复制相似问题