flex布局(三) : 多行显示

flex布局(三) : 多行显示

4. flex-wrap 决定items的换行

控制item的多行显示

  • nowrap(默认) :单行显示,如果容器container宽度不够,则压缩item宽度适应
  • wrap :多行显示,每一行平分容器container高度
  • wrap-reverse :多行显示,交叉轴上对调顺序。大多数情况下不会使用这个属性
<style>
.container{
    width: 500px;
    height: 400px;
    border: 1px solid #000;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: flex-start;
}
.item{
    width: 100px;
    height: 100px;
    color: #fff;
    text-align: center;
    line-height: 100px;
}
.container{
    /* 设置多行显示 */
    flex-wrap: nowrap;
    flex-wrap: wrap;
    flex-wrap: wrap-reverse;
}

</style>

<body>
    <div class="container">
        <div class="item" style="background: #f00;">item1</div>
        <div class="item" style="background: #0f0;">item2</div>
        <div class="item" style="background: #00f;">item3</div>
        <div class="item" style="background: #f00;">item4</div>
        <div class="item" style="background: #0f0;">item5</div>
        <div class="item" style="background: #00f;">item6</div>
        <div class="item" style="background: #f00;">item7</div>
        <div class="item" style="background: #0f0;">item8</div>
        <div class="item" style="background: #00f;">item9</div>
    </div>
</body>

在这里插入图片描述

5. flex-flow direction和wrap的复合属性

flex-direction和flex-wrap的组合缩写属性

  • flex : flex-direction || flex-wrap

通常情况设置为flex-flow:row wrap

6. align-content 决定行与行之间的排列方式

控制行与行之间的对齐方式,只用在多行显示。需要设置flex-wrap: wrap

  • stretch(默认)
  • flex-start
  • flex-center
  • flex-end
  • space-between
  • space-evently
  • space-around
<style>
.container{
    width: 500px;
    height: 400px;
    border: 1px solid #000;

    /* flex布局的排列方式 */
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: flex-start;
}
.item{
    width: 100px;
    height: 100px;
    color: #fff;
    text-align: center;
    line-height: 100px;
}
.container{
    /* 设置多行显示 */
    flex-wrap: wrap;
    align-content: stretch;
    align-content: flex-start;
    align-content: center;
    align-content: flex-end;
    align-content: space-between;
    align-content: space-evenly;
    align-content: space-around;
    
}

</style>

<body>
    <div class="container">
        <div class="item" style="background: #f00;">item1</div>
        <div class="item" style="background: #0f0;">item2</div>
        <div class="item" style="background: #00f;">item3</div>
        <div class="item" style="background: #f00;">item4</div>
        <div class="item" style="background: #0f0;">item5</div>
        <div class="item" style="background: #00f;">item6</div>
        <div class="item" style="background: #f00;">item7</div>
        <div class="item" style="background: #0f0;">item8</div>
        <div class="item" style="background: #00f;">item9</div>
       
    </div>
</body>

在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值