wxss实现多列显示

今天主要通过三种方式实现:
wxml代码:

<view class="container">
  <view class="viewContainer" wx:for="{{cells}}">
    <image class="cellIcon" src="{{item.imageUrl}}"></image>
    <view>{{item.title}}</view>
  </view>
</view>

1、通过浮动float实现

.container{
  margin: 0;
  padding: 0;
  display: block;
}
.viewContainer{
    float: left;
    width: 33.3%;
    height: 150px;
    text-align: center;
    border: 1px solid lightblue;
    box-sizing: border-box;

}
.cellIcon{
  width: 100%;
  height: 120px;
}

2、 flex-direction实现:

.container{
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  text-align: center;
}
.viewContainer{
  width: 33.3%;
  padding: 5px;
  box-sizing: border-box;
  border: 1px solid lightblue;
  
}
.cellIcon{
  width: 100%;
  height: 110px;
}

3、通过 column-count实现

.container{
  margin: 0;
  padding: 0;
  display: block;
  column-count: 2;
  column-gap: 0px;
  }
.viewContainer{
    height: 150px;
    text-align: center;
    border: 1px solid lightblue;
    box-sizing: border-box;
    background: red;
}
.cellIcon{
  width: 100%;
  height: 120px;
}

最终效果:


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    wzhiq896阅读 1,806评论 0 2
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    love2013阅读 2,339评论 0 11
  • 移动开发基本知识点 一.使用rem作为单位 html { font-size: 100px; } @media(m...
    横冲直撞666阅读 3,519评论 0 6
  • H5移动端知识点总结 阅读目录 移动开发基本知识点 calc基本用法 box-sizing的理解及使用 理解dis...
    Mx勇阅读 4,631评论 0 26
  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,814评论 1 92