zoukankan      html  css  js  c++  java
  • flex 增长与收缩

    flex:auto  将增长值与收缩值设置为1,基本大小为 auto 。

    flex:none. 将增长值与收缩值设置为0,基本大小为 auto 。也就是固定大小。

    增长:

    基本大小 + 额外空间 *(增长系数 / 增长系数总和)   

    按比例划分额外空间,然后各自分配。

    缩小:

    基本大小 – 溢出大小 *(缩小系数 * 基本大小 / 各各缩小系数 * 自身大小 之和)

    #container {
    
      display: flex;
    
      flex-wrap: nowrap;
    
    }

     flex-shrink: 1并非严格等比缩小,它还会考虑弹性元素本身的大小

    • 容器剩余宽度:-70px
    • 缩小因子的分母:1*50 + 1*100 + 1*120 = 270 (1为各元素flex-shrink的值)
    • 元素1的缩小因子:1*50/270
    • 元素1的缩小宽度为缩小因子乘于容器剩余宽度:1*50/270 * (-70)
    • 元素1最后则缩小为:50px + (1*50/270 *(-70)) = 37.03px

    均匀增长(直接按设置的比例增长)

    将基本大小设置为:0,那么收缩值就不在适用了。

    flex:值;或 flex-shrink:0;flex-basis:0;

    如:flex:1; flex:2; flex:3. 那么第二个为第一个的2倍宽度,第三个为第一个的3倍宽度。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            * {
                margin: 0;
                padding: 0px;
            }
            .flexbox-row{
                margin: 50px auto;
                display: flex;
                flex-direction: row;
                width: 120px;
                height: 320px;
                border: 1px #ccc solid;
            }
            .box1{
                flex: 1;
                height: 50px;
            }
            .box2{
                flex: 2;
                height: 50px;
            }
            .box3 {
                flex: 1.5;
                height: 30px;
            }
        </style>
    </head>
    <body>
    
    <div class="flexbox-row">
        <div class="box box1" style="background-color:coral;">A</div>
        <div class="box box2" style="background-color:lightblue;">B</div>
        <div class="box box3" style="background-color:khaki;">C</div>
    </div>
    
    </body>
    </html>
  • 相关阅读:
    pytest知识梳理
    linux服务器时间不同步解决
    python re 多行匹配模式
    nginx--知识梳理
    tomcat--知识梳理
    利用springboot 重定向到静态资源功能,下载一些文件文件
    调试C++代码内存释放,在VS2019控制台显示内存泄露
    C++Primer第五版 第九章 习题9.22
    nginx 配置中间证书
    云苍穹消息推送代码
  • 原文地址:https://www.cnblogs.com/whnba/p/10457877.html
Copyright © 2011-2022 走看看