一句话,scroll-view的子元素要inline-block,父元素white-space: nowrap;就可以横向排列。但是这个时候,子元素有最后一个元素有可能是显示不全的,需要在scroll-view加上overflow: scroll;。就可以完美解决问题,直接上代码吧。本人亲自踩此坑,如有帮助,请点赞哦,好用不点赞就是耍流氓,哈哈,白嫖。
<view class="title-con">
<view class="conclude-title">已选</view>
<scroll-view class="scroll-view_H" scroll-x="true">
<block wx:for="{{selectedStrategy}}" wx:key="strategy_id">
<view class="filter-item">
<!-- <text>{{item.strategy_name}}</text> -->
{{item.strategy_name}}
<image src="/images/close.png" class="close" bindtap="handleCloseStrategy" data-catid="{{item.strategy_cat_id}}" data-strategyid="{{item.strategy_id}}" />
</view>
</block>
</scroll-view>
</view>
.title-con {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
height: 62rpx;
width: 100%;
flex-direction: row;
align-items: center;
overflow: visible;
white-space: nowrap;
}
.scroll-view_H {
width: 100%;
overflow: scroll;
}
.filter-item {
padding-left: 28rpx;
padding-right: 28rpx;
line-height: 62rpx;
background: rgba(237, 249, 249, 1);
border-radius: 40rpx;
text-align: center;
margin-right: 18rpx;
color: rgba(55, 194, 188, 1);
display: inline-block;
}
网友评论