html - 使 div 高度延伸到另一个 div

标签 html css

这是我的代码:http://jsfiddle.net/fxWg7/4041/

我想让左侧边栏动态地向下延伸到页脚。页脚是粘性页脚,这意味着无论主要内容有多长,它都会留在下面。

无论主要内容的高度如何,我都希望左侧边栏向下延伸到页脚。

html {
  position: relative;
  min-height: 100%;
}

body {
  margin: 0 0 50px;
  /* bottom = footer height */
}

.container {
  height: auto;
  overflow: hidden;
}

.left {
  width: 180px;
  float: left;
  background: #aafed6;
}

.right {
  float: none;
  /* not needed, just for clarification */
  background: #e8f6fe;
  /* the next props are meant to keep this block independent from the other floated one */
  width: auto;
  overflow: hidden;
}

footer {
  width: 100%;
  background-color: #000;
  color: #fff;
  padding: 1em;
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
}
<div class="container">

  <div class="left">
    left content fixed width
    <br>
    <br> I want this to extend to footer!
  </div>

  <div class="right">
    right content flexible width
    <br>
    <br> right content flexible width
    <br>
    <br> right content flexible width
    <br>
    <br> right content flexible width
    <br>
    <br> right content flexible width
  </div>

</div>

<footer>
  This is my footer.
</footer>

最佳答案

更新:

下面的 css 代码可以做到这一点:

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

.container {
  height: 100%;
  display: flex;
  flex: 1;
}

.left {
  width: 180px;
  background: #aafed6;
}

.right {
  width: auto;
  background: #e8f6fe;
}

footer {
  width: 100%;
  background-color: #000;
  color: #fff;
  padding: 1em;
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
}

查看 jsfiddle - http://jsfiddle.net/jalenconner/be71229w/1/

此解决方案使用 CSS Flexbox,您可以在此处了解更多信息:https://css-tricks.com/snippets/css/a-guide-to-flexbox/

关于html - 使 div 高度延伸到另一个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43749246/

相关文章:

javascript - 溢出滚动框左右移动 div

javascript - 为什么可以用new Image 而不能用new Div 或new Span?

javascript - HTML5 <音频>:单击下一首歌曲时停止加载/缓冲

javascript - 全屏视频 Sprite

css - 模糊图像然后恢复正常状态

css - 当你有 6-7 个页面要加载时,如何制作标签页?(css/jquery)

javascript - css transitions 影响之前修改过的 css 属性

css - 如何忽略使用 .htaccess 重写 css 文件

javascript - 具有多个过滤器的 jQuery 复选框

javascript - 添加新子元素时,父容器仅将子元素包裹到屏幕边缘(首选 IE 11 支持)