关键:

1
2
flex-shrink: 0;
white-space: nowrap;

示例:

Html

1
2
3
4
5
6
7
8
9
10
11
12
<view class="padding-style">
<view class='overflow-company-second'>
<view class="special-list">
<view class='active'>1</view>
<view>2</view>
<view>3</view>
<view>4</view>
<view>5</view>
<view>6</view>
</view>
</view>
</view>

css

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
.padding-style {
padding: 0 28rpx;
}


.overflow-company-second {
overflow: hidden;
height: 88rpx;
border-bottom: 1px solid #ccc;
}


.special-list {
line-height: 88rpx;
font-size: 30rpx;
display: flex;
overflow-x: auto;
justify-content: space-between;
padding-bottom: 40rpx;
}


.special-list>view {
text-align: center;
font-size: 30rpx;
color: #283B42;
font-weight: bold;
flex-basis: 172rpx;
flex-shrink: 0;
white-space: nowrap;
}


.special-list>view.active {
position: relative;
}


.special-list>view.active::before {
content: "";
display: block;
clear: both;
width: 120rpx;
height: 6rpx;
background-image: linear-gradient(90deg, #ea6f5a 58%, #eebeb6 100%);
border-radius: 40rpx;
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
}

总结

display: flex flex布局
justify-content: space-between 位于首尾两端的子容器两端对齐
flex-basis: 172rpx 子容器基准大小 表示在不伸缩的情况下子容器的原始尺寸
flex-shrink: 0 收缩比例
white-space: nowrap 规定段落中的文本不进行换行
overflow-x: auto 横向溢出元素的内容区域添加滚动