国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > Flex > 正文

CSS3 Flexbox中flex-shrink屬性的用法示例介紹

2024-09-08 18:17:11
字體:
來源:轉載
供稿:網友

在CSS3 Flexbox中flex-shrink屬性定義為:

This <number> 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’. 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的實際結果就會越小

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洱源县| 通化市| 宜昌市| 平山县| 乡城县| 宁海县| 白银市| 电白县| 贵南县| 太原市| 庄河市| 罗平县| 屏山县| 天峨县| 延津县| 九江县| 金寨县| 洪洞县| 剑河县| 新蔡县| 河东区| 大邑县| 肇东市| 吉首市| 阿合奇县| 砀山县| 都江堰市| 威远县| 巴东县| 绥滨县| 安吉县| 屏南县| 萍乡市| 邯郸市| 浦县| 山阴县| 泸西县| 西和县| 汾阳市| 陈巴尔虎旗| 根河市|