
批改狀態(tài):合格
老師批語:
以上屬性簡(jiǎn)寫:
flex: 放大因子 收縮因子 大小;
例:flex: 2 2 10rem;
默認(rèn)值:flex: 0 1 auto; (initial)
1 1 auto = auto
0 0 auto = none
默認(rèn)效果
flex-grow
CSS
.container>.item {
padding: 1rem;
background-color: lightsteelblue;
border: 1px solid black;
flex-basis: 10rem;
}
.container>.item:first-of-type {
flex-grow: 1;
}
.container>.item:nth-of-type(2) {
flex-grow: 2;
}
.container>.item:nth-of-type(3) {
flex-grow: 3;
}
.container>.item:last-of-type {
flex-grow: 4;
}
flex-shrink
CSS
.container>.item {
padding: 1rem;
background-color: lightsteelblue;
border: 1px solid black;
flex-basis: 10rem;
}
.container>.item:first-of-type {
flex-shrink: 1;
}
.container>.item:nth-of-type(2) {
flex-shrink: 2;
}
.container>.item:nth-of-type(3) {
flex-shrink: 3;
}
.container>.item:last-of-type {
flex-shrink: 4;
}
當(dāng)容器寬度足夠容納所有項(xiàng)目時(shí):
當(dāng)容器寬度不夠時(shí)開始收縮:
下圖中,容器總width為 366 < 400, 此時(shí)子項(xiàng)目大概寬度:
item1-85, item2-89, item3-92, item4-96
注:容器寬度過小時(shí),會(huì)從item3-item1開始逐漸妥協(xié),即item3-item1寬度逐漸與item4相等,最后每個(gè)item寬度相等
.container>.item:nth-of-type(3) {
flex-grow: 3;
align-self: flex-start;
}
.container>.item:nth-of-type(3) {
flex-grow: 3;
align-self: flex-start;
position: absolute;
background-color: blanchedalmond;
left: 5rem;
top: 5rem;
}
order: value;
數(shù)字大靠后排列,數(shù)字小靠前排列
.container>.item:nth-of-type(3) {
flex-grow: 3;
order: 20
}
.container>.item:last-of-type {
flex-grow: 4;
order: -1;
}
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)