首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >flexbox在另一个Flexbox中?

flexbox在另一个Flexbox中?
EN

Stack Overflow用户
提问于 2017-02-13 09:44:34
回答 1查看 10.5K关注 0票数 6

我在试着让flexbox在flexbox里工作。虽然第一个(包装) flexbox可以工作,但里面的那个什么也不做。有没有办法让这件事起作用呢?

我想要做的是有效地拥有两个粘性的脚注,并让它们的高度都能到达脚注。

代码语言:javascript
复制
html, body {
  height: 100%;
  margin: 0; padding: 0;  /* to avoid scrollbars */
}

#wrapper {
  display: flex;  /* use the flex model */
  min-height: 100%;
  flex-direction: column;  /* learn more: http://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ */
}

#header {
  background: yellow;
  height: 100px;  /* can be variable as well */
  
}

#body {
  flex: 1;
  border: 1px solid orange;
  height: 100%:
}
#wrapper2 {
  display: flex;  /* use the flex model */
  min-height: 100%;
  flex-direction: column;
}
#body2 {
  border: 1px solid purple;
  flex: 1;
}
#footer2 {
  background: red;
  flex: 0;
}

#footer{
  background: lime;
}
代码语言:javascript
复制
<div id="wrapper">
  <div id="body">Bodyof<br/>
    variable<br/>
    height<br/>
    <div id="wrapper2">
    <div id="body2">
    blah
    </div>
    <div id="footer2">
    blah<br />
    blah
    </div>    
    </div>
    </div>
  <div id="footer">
    Footer<br/>
    of<br/>
    variable<br/>
    height<br/>
  </div>
</div>

JS Fiddle

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-13 10:13:57

你就快到了。只有两步之遥:

借助flex: 1.,

  1. Make #body a flex
    1. .wrapper2 full height

(我还去掉了百分比高度。您不需要它们。)

代码语言:javascript
复制
body {
  margin: 0;
}
#wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
#header {
  background: yellow;
  height: 100px;
}
#body {
  flex: 1;
  border: 1px solid orange;
  display: flex;            /* new */
  flex-direction: column;   /* new */
}
#wrapper2 {
  display: flex;
  flex-direction: column;
  flex: 1;                  /* new */
}
#body2 {
  border: 1px solid purple;
  flex: 1;
}
#footer2 {
  background: red;
}
#footer {
  background: lime;
}
代码语言:javascript
复制
<div id="wrapper">
  <div id="body">
    Bodyof
    <br>variable
    <br>height
    <br>
    <div id="wrapper2">
      <div id="body2">blah</div>
      <div id="footer2">
        blah
        <br>blah
      </div>
    </div>
  </div>
  <div id="footer">
    Footer
    <br>of
    <br>variable
    <br>height
    <br>
  </div>
</div>

完成上述调整后,您可以使用以下命令将内部(红色)页脚固定到底部:

容器上的

  • flex: 1,这就是您所拥有的,or
  • margin-bottom: auto on #body2,or
  • justify-content: space-between on #footer2,or
  • justify-content: space-between on the container (#wrapper2)
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42195456

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档