zoukankan      html  css  js  c++  java
  • flex-shrink值的计算

    flex-shrink为弹性盒模型中,当弹性项不断行,并且所有弹性项的宽度只和大于弹性盒模型的可分配空间时,弹性项的收缩程度。

    找到英文资料对flex-shrink的定义描述:

    flex-shrink规定了弹性收缩系数。当分配负可用空间时,弹性收缩系数决定了弹性项相对于弹性容器中的其他弹性项的收缩程度。当省略时,默认设置为1。

    注意:当分配负可用空间时,弹性收缩系数乘以弹性项基本尺寸。这使得分配负空间与弹性项收缩的程度成比例,如此以来,在大的弹性项有明显的减少前,小的弹性项不会收缩到0。

    W3C中对于flex-shrink原文定义:

    This component sets flex-shrink longhand and specifies the flex shrink factor, which determines how much the flex item will shrink relative to the rest of the flex items in the flex container when negative free space is distributed. When omitted, it is set to 1.

    Note: The flex shrink factor is multiplied by the flex base size when distributing negative space. This distributes negative space in proportion to how much the item is able to shrink, so that e.g. a small item won’t shrink to zero before a larger item has been noticeably reduced.

    原文链接:https://www.w3.org/TR/css-flexbox-1/#flex-flex-shrink-factor

    flex-shrink计算实例

    <!DOCTYPE html>
    <html>
    
    <head>
        <meta charset="utf-8">
        <title>flex-shrink计算实例</title>
        <style>
            #content {
                display: flex;
                 500px;
            }
    
            .boxA {
                flex-shrink: 1;
                flex-basis: 50px;
            }
    
            .boxB {
                flex-shrink: 2;
                flex-basis: 100px;
            }
    
            .boxC {
                flex-shrink: 3;
                flex-basis: 150px;
            }
    
            .boxD {
                flex-shrink: 4;
                flex-basis: 200px;
            }
    
            .boxE {
                flex-shrink: 5;
                flex-basis: 250px;
            }
    
        </style>
    </head>
    
    <body>
    
        <div id="content">
            <div class="boxA" style="background-color:red;">A</div>
            <div class="boxB" style="background-color:lightblue;">B</div>
            <div class="boxC" style="background-color:yellow;">C</div>
            <div class="boxD" style="background-color:brown;">D</div>
            <div class="boxE" style="background-color:lightgreen;">E</div>
        </div>
    </body>
    
    </html>
    

      

    本例中A、B、C、D、E的flex-basic值分别设为50px、100px、150px、200px、250px,flex-shrink的值分别设置为:1、2、3、4、5。

    分配负空间的量:50+100+150+200+250-500=250px;

    A应该分配的份额比例:50x1/(50x1+100x2+150x3+200x4+250x5)=50/2750;

    A分配负空间的量:250x50/2750≈4.545px;

    A实际弹性长度:50-4.545=45.455px;

  • 相关阅读:
    django2.2/mysql ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
    orm练习题
    url的匹配问题
    集成抽象类后出现的问题
    迅为IMX6Q开发板上移植mplayer
    迅为i.MX6ULL开发板原理图分析介绍
    性价比高又能较好的学习嵌入式ARM+Linux的开发板
    适合初学者的linux开发板
    IMX6ULL开发板
    i.MX6ULL开发板终结者资料介绍
  • 原文地址:https://www.cnblogs.com/f6056/p/11662998.html
Copyright © 2011-2022 走看看