flex知识点归纳

1.flex-shrink

<div id="content">
  <div class="box" style="background-color:red;">A</div>
  <div class="box" style="background-color:lightblue;">B</div>
  <div class="box" style="background-color:yellow;">C</div>
  <div class="box1" style="background-color:brown;">D</div>
  <div class="box1" style="background-color:lightgreen;">E</div>
</div>
#content {
  display: flex;
  width: 500px;
}
#content div {
  flex-basis: 120px;
}
.box { 
  flex-shrink: 1;
}
.box1 { 
  flex-shrink: 2; 
}

分析: 最外层容器500;每个子容器120;则子容器总长600;box收缩比例为1,box1的收缩比例为2;则所有子元素的总收缩比为7;

          则,box的收缩长度为原厂的1/7;剩余长度为原来的6/7;即120*(6/7);box1为(120*(5/7))

参考:https://codepen.io/pen/?editors=1100

2.flex

1)flex: auto;---->flex: 1 1 auto;

  相当于:flex-grow:1;flex-shrink:1;flex-basis:auto

2)flex: none --->flex: 0 0 auto;

3)flex: initial --->flex: 0 1 auto;

4)flex: 正数(无单位) -->flex:  <positive-number> 1 0;

5)flex: 正数(有单位) --> flex: 1 1 有单位正数;

6)flex: 正数 无单位正数 --> flex:正数 无单位正数 0;

7)flex: 正数 有单位正数 --> flex: 正数 1 有单位正数;

实际应用:

如果想要一个容器中的所有子元素宽度均分。

可以使用flex: 1;

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .parent {
            width: 100%;
            height: 500px;
            display: flex;
        }
        .item {
            flex: 1;
            background-color: antiquewhite;
        }
        .item:not(:last-child) {
            margin-right: 20px;     
        }
    </style>
</head>
<body>
        <div class="parent">
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
        </div>
</body>
</html>

 

转载于:https://www.cnblogs.com/lyraLee/p/10563866.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值