flex-direction: column没有效果?

新手上路,请多包涵

flex-direction设置了column没有效果

<section class="layout flexbox">
    <style>
        .layout.flexbox .top-center-bottom{
            display: flex;
            flex-direction: column;
        }
        .layout.flexbox .top{
            height: 100px;
            background-color: red;
        }
        .layout.flexbox .center{
            flex: 1;
            background: yellow;
        }
        .layout.flexbox .bottom{
            height: 100px;
            background-color: blue;
        }
    </style>
    <article class="top-center-bottom">
        <div class="top"></div>
        <div class="center">
            <h1>flexbox解决方案</h1>
        </div>
        <div class="bottom"></div>
    </article>
</section>

图片描述

阅读 5.6k
2 个回答
.layout.flexbox .top-center-bottom {
  display: flex;
  height: 400px;
  flex-direction: column;
}
.layout.flexbox .top {
  height: 100px;
  flex: 0 0 100px;
  background-color: red;
}
.layout.flexbox .center {
  flex: 1;
  background: yellow;
}
.layout.flexbox .bottom {
  height: 100px;
  flex: 0 0 100px;
  background-color: blue;
}

父元素的高度要有个值

flex-direction:column不就是垂直布局的意思?

猜想楼主的意思可能是想把页面整个撑满吧,这样的话需要

htmlbody和父容器均要设置高度为100%

html,body{ margin:0; height:100% }/*貌似很多人都会忘记这一点*/
.layout { height:100% }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题