flex-shrink属性怎么在CSS3中使用

今天就跟大家聊聊有关flex-shrink属性怎么在CSS3中使用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

义马网站建设公司创新互联公司,义马网站设计制作,有大型网站制作公司丰富经验。已为义马1000+提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的义马做网站的公司定做!

在CSS3 Flexbox中flex-shrink属性定义为:

This <number> component sets &lsquo;flex-shrink&rsquo; 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 &lsquo;1&rsquo;. The flex shrink factor is multiplied by the flex basis when distributing negative space.


通俗来讲就是当flex items的大小超过了flex container时, 各个flex item的压缩比例, 请看下面的示例:

代码如下:

<style> 
#container div { 
height: 200px; 
width: 60px; 
} 
#test1 { 
background-color: blue; 
flex-shrink: 1; 
} 
#test2 { 
background-color: yellow; 
flex-shrink: 0.5; 
} 
</style> 
<div id="container"> 
<div id="test1"></div> 
<div id="test2"></div> 
</div>


<div id="test1">与<div id="test2">的宽度总和是120px, 超过了<div id="container">的宽度100px, 超过的大小为20px, 那么container为了装下两个子div,两个子div的宽度就必须减少20px,那么每个子div的宽度减少多少呢? 这个时候就需要flex-shrink属性来分配了,每个子div的实际显示宽度计算方法公式为:

实际值 = 计划值 - 总差值 * flex-shrink/(flex-shrink和)

根据上面的公式我们可以计算出<div id="test1">与<div id="test2">的实际宽度值分别为:

代码如下:

<div id="test1">: width = 60 - 20 * 1 / (1 + 0.5) = 47px 
<div id="test2">: width = 60 - 20 * 0.5 / (1 + 0.5) = 53px


根据以上结果可知flex-shrink值越大,flex item的实际结果就会越小

看完上述内容,你们对flex-shrink属性怎么在CSS3中使用有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。

文章标题:flex-shrink属性怎么在CSS3中使用
链接URL:https://www.cdcxhl.com/article34/gshpse.html

成都网站建设公司_创新互联,为您提供软件开发企业建站企业网站制作网站策划小程序开发定制开发

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

h5响应式网站建设