页脚停留在底部,但是在浏览器调整大小时,页脚被推到内容的顶部

用户名

这是指向Codepen的链接http://codepen.io/Kwits/pen/mVRqbx?editors=110

所以这是两列布局,我计划在两者的底部都有一个页脚。左列是固定的,而右列是可滚动的。

问题是,如果将浏览器的高度拉高,则页脚随之而来。理想情况下,我希望它在导航div之前停止。

感谢您的帮助,我已经坚持了几个小时。

这是我的HTML

<div class="left">
  <header>
    <div class="logo">
      <img src="images/Logo.png" alt="">
      <h1 id="logo_title">Business name</h1>
    </div>
  </header>

  <ul class="nav">
    <li>
      <a href="index.html"><img src="images/home_btn.png" class="home"></a>
    </li>
    <li>
      <a href="about.html"><img src="images/about_btn.png" class="about"></a>
    </li>
    <li><img src="images/curriculum_btn.png"></li>
    <li><img src="images/contact_btn.png"></li>
  </ul>

  <div class="footer-left">
    <p>Address</p>
    <p>City</p>
    <p>Post Code</p>
    <p>Phone Number</p>
  </div>
</div>
<div class="right">
  <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum,
    you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary
    of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc..</p>
</div>

这是CSS

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

.right {
  height: 100%;
  position: absolute;
  border-left: 2px solid grey;
  background: #74C279;
  overflow: auto;
  z-index: 0;
  left: 303px;
  padding-left: 25px;
  padding-right: 25px;
  padding-top: 50px;
}

.left {
  border-right: 5px solid gray;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  width: 300px;
  background: #F0C090
}

.footer-left {
  width: 100%;
  position: absolute;
  bottom: 0;
  font-size: 22px;
  line-height: 10px;
  text-align: center;
}
人们

您需要使用javascript函数将 min-height 左列的设置 .left header s height + .left nav s height + .left .footer-left s height。此功能必须在页面加载以及任何可能更改以下三个子项中任何一个的高度的事件上运行 left

在尝试编写js函数以针对所有情况动态调整CSS时,我意识到可以通过flexbox轻松实现。这是一个解决方案相关代码:

.left {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.left .nav {
  flex-grow: 1;
}

请注意,我还从中删除了该position属性.footer-left如果在其中添加任何其他元素.left,则应将应用于flex-grow: 1之前的最后一个子元素.footer-left这表明该元素的高度根据需要增加,因此页脚保持向下。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

让页脚停留在所有内容的底部

来自分类Dev

页脚不停留在底部

来自分类Dev

使页脚停留在页面底部

来自分类Dev

页脚拒绝停留在底部

来自分类Dev

页脚不停留在页面底部

来自分类Dev

页脚不停留在页面底部

来自分类Dev

页脚不停留在页面底部

来自分类Dev

即使页面内容小于屏幕内容,如何使页脚始终停留在页面底部?

来自分类Dev

使页脚停留在窗口底部(而不是页面)并且不重叠内容

来自分类Dev

我的页脚停留在视口的底部

来自分类Dev

动态停留在底部的html页面上的页脚

来自分类Dev

Div页脚不会停留在底部

来自分类Dev

页脚不会停留在页面底部

来自分类Dev

页脚不会停留在页面底部

来自分类Dev

Bootstrap页脚不停留在页面底部

来自分类Dev

页脚不会停留在页面底部

来自分类Dev

我无法让我的页脚停留在底部

来自分类Dev

页脚不停留在内容下方

来自分类Dev

如何使背景图片停留在浏览器底部

来自分类Dev

如何在滚动时使简单的<audio>元素停留在浏览器窗口的底部?

来自分类Dev

通过滚动将表格行停留在浏览器顶部

来自分类Dev

页脚停留在页面中间

来自分类Dev

当内容不超过滚动高度时,CSS“内容页脚”会停留在底部,但当内容超出内容时会随内容一起流动

来自分类Dev

CSS页脚在小尺寸屏幕上不会停留在底部

来自分类Dev

页面扩展时,网站页脚绝对不会停留在底部

来自分类Dev

调整浏览器大小时内容重叠

来自分类Dev

我的页脚不会停留在我的主要内容范围内

来自分类Dev

粘性页脚不会停留在动态Rails内容的下方

来自分类Dev

除非有多余的内容,否则如何将页脚节设置为停留在底部,我们需要滚动以使用flex进行查看

Related 相关文章

热门标签

归档