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;

  • 相关阅读:
    springboot:springboot初识(相关概念、新建项目)
    ssm项目无法加载静态资源
    js:初识(相关概念、js代码的书写位置、注释方式、输入输出语句)
    lucene:索引维护(删除、更新、查询)
    数据库连接池:Durid(执行流程、工具类)
    redis:HyperLogLog&发布订阅(HyperLogLog的概念和命令、redis的发布订阅)
    redis:zset(赋值、取值、删除、修改分数)
    css:css3新特性(过渡)
    css:css3新特性(盒子模型的box-sizing属性、图片模糊处理、calc函数)
    css:css3新特性(属性选择器、结构伪类选择器)
  • 原文地址:https://www.cnblogs.com/f6056/p/11662998.html
Copyright © 2011-2022 走看看