国产探花免费观看_亚洲丰满少妇自慰呻吟_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的實際結果就會越小

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贵南县| 常德市| 淮滨县| 鄂托克前旗| 射洪县| 肇东市| 邯郸市| 夏邑县| 平陆县| 探索| 新疆| 馆陶县| 万州区| 萝北县| 临城县| 寿阳县| 舞阳县| 高密市| 日土县| 碌曲县| 綦江县| 定南县| 湄潭县| 威远县| 随州市| 绵竹市| 凤冈县| 资溪县| 三江| 大邑县| 建湖县| 兰西县| 阿尔山市| 灵寿县| 马龙县| 台湾省| 佳木斯市| 武川县| 大名县| 理塘县| 临桂县|