<view class="rega" v-if="isActive==1"> <text style="margin: 10px;">热门城市</text> <block class="cities row-item flexbox" v-for="(item,index) in hotcities" key="index"> <view class="hotcities—item"> <text>{{item.names}}</text> </view> </block> </view>.row-item { display: flex; flex-direction: row; //设置布局方向为水平 } .bottom_title { text-align: center; margin-left: 20px; } .active { font-weight: bold; border-bottom: 2px solid orange; } .flexbox { display: flex; flex-wrap: wrap; justify-content: space-between; } .hotcities—item { width: 23%; margin-bottom: 10px; border: 1px solid #ccc; padding: 5px; }让block标签里面显示的东西横向布局,每行显示四个,多的显示在下一行
时间: 2024-02-19 18:03:57 浏览: 68
可以在`.flexbox`样式中添加`flex-basis: 23%;`来设置每个`.hotcities—item`元素的宽度为23%,并在`.row-item`样式中添加`flex-wrap: wrap;`来设置元素换行,然后使用`justify-content: space-between;`来设置每行元素之间的间距。最终代码如下:
```
.row-item {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.hotcities—item {
flex-basis: 23%;
margin-bottom: 10px;
border: 1px solid #ccc;
padding: 5px;
}
```
相关问题
<view class="rega" v-if="isActive==1"> <text style="margin: 10px;">热门城市</text> <block class="cities row-item" v-for="(item,index) in hotcities" key="index"> <view class="hotcities—item"> <text>{{item.names}}</text> </view> </block> </view>让这个block里面显示的内容横向排列,每行显示4个,显示的每个元素都要有边框
可以将这个block的class属性改为"cities row-item flexbox",并在CSS样式中添加以下代码:
```
.flexbox {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.hotcities—item {
width: 23%;
margin-bottom: 10px;
border: 1px solid #ccc;
padding: 5px;
}
```
这样就可以让block里面的内容横向排列,每行显示4个,并且每个元素都有边框了。
<view class="rega" v-if="isActive==3"> <block v-for="(item,index) in team" key="index"> <view class="zxc"> <view style="display: table;width: 100%;margin-left: -25px;"> <view style="display: table-cell;width: 30%;text-align: center;"> <text>{{index+1}}</text> </view> <view style="display: table-cell;width: 30%;text-align: center;"> <text>{{item.name}}</text> </view> <view style="display: table-cell;width: 30%;text-align: center;"> <text>{{item.phone}}</text> </view> </view> </view> </block> </view>.zxc { float: left; width: 90%; height: 110px; background-color: #fff; margin-top: 20px; margin-left: 18px; border-radius: 10px; }让显示的内容位于zxc标签的上下左右的最中间
可以使用flex布局来实现将内容在zxc标签的上下左右的最中间显示。具体做法是在.zxc样式中设置display为flex,然后使用justify-content和align-items属性将内容在水平和垂直方向上居中。示例代码如下:
```
.zxc {
display: flex;
justify-content: center;
align-items: center;
float: left;
width: 90%;
height: 110px;
background-color: #fff;
margin-top: 20px;
margin-left: 18px;
border-radius: 10px;
}
```
阅读全文