flex-demo.wxss
828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* flex子元素自适应宽度示例样式 */
.container {
padding: 20rpx;
}
.section {
margin-bottom: 40rpx;
}
.title {
font-size: 32rpx;
font-weight: bold;
margin-bottom: 20rpx;
color: #333;
}
.flex-container {
display: flex;
width: 100%;
gap: 20rpx;
margin-bottom: 20rpx;
}
.flex-item {
height: 80rpx;
display: flex;
align-items: center;
justify-content: center;
border-radius: 10rpx;
color: white;
font-size: 28rpx;
}
.item1 {
background-color: #ff6b6b;
}
.item2 {
background-color: #4ecdc4;
}
.item3 {
background-color: #45b7d1;
}
/* 平均分配宽度 */
.flex-item {
flex: 1;
}
/* 根据内容自适应宽度 */
.auto-width {
flex: 0 1 auto;
/* flex-grow: 0 (不扩展)
flex-shrink: 1 (可以收缩)
flex-basis: auto (根据内容确定基础宽度) */
}