CSS弹性盒子布局

CSS弹性盒子布局

案例:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>弹性盒子</title>
    <style>
        .father{
            display: flex;
            width: 400px;
            background-color: lightskyblue;
        }
        .item{
            width: 100px;
        }
    </style>
</head>
<body>
    <div class="father" >
        <div class="item" style="background:lightpink;">1</div>
        <div class="item" style="background:lightcoral;">2</div>
        <div class="item" style="background:lightgreen;">3</div>
    </div> 
</body>
</html>

方法:

给父级元素设置样式,例如项目中经常用到的:

.father{
  display: flex;
  /*
  just-cotent: flex-start; //默认值
  flex-wrap: nowrap;//默认值
  */
  justify-content: space-around;//中间和两边间距相同
  flex-wrap: wrap;//必要位置换行
}

改变样式:

可以利用just-content横向布局,flex-direction纵向排列。
align-itemsalign-content可以改变该弹性盒子在容器的位置。
flex-wrop决定必要是是否换行,和换行方向。

just-content

  1. flex-start //横向连续排列
  2. flex-end //从尾部开始横向连续排列
  3. center //中间横向连续排列
  4. space-between //中间间隔相同
  5. space-around //中间 两边间隔都相同
  6. initial //继承父级

flex-direction:

  1. row //横向排列
  2. row-reverse //相反顺序横向排列
  3. column //纵向排列
  4. column-reverse //相反顺序纵向排列

align-items:

  1. strech //拉伸适应容器
  2. center //容器中心
  3. flex-start //容器开头
  4. flex-end //容器末尾
  5. baseline //容器基线

flex-wrop:

  1. nowrap //默认值
  2. wrap //必要位置换行
  3. wrap-reverse //相反顺序换行

align-content:center对单行无效,而align-items:center对单行还是多行都有效果,align-items更好。

补充:
flex-flow:是flex-direction和flex-wrop的简写。默认值为row nowrap。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值