微信小程序(五)

flex布局

弹性布局。display:flex表示使用flex布局,主要有下面几个属性flex-direction,flex-wrap,justify-content。
在flex容器中的元素,会按order进行排序展示,值越小越先展示,flex是占比,设置了flex则元素的width就相当于失效了。元素宽度等于flex占屏幕宽度的比例。

这几个属性会相互作用,比如指定了逆向,再指定order。

wxml中
<view class="container">
   <view class='a size'>a</view>
   <view class='b size'>b</view>

   <view class='c size'>c</view>

   <view class='d size'>d</view>

   <view class='e size'>e</view>

</view>


wxss中
.container{
  display: flex;
  /* flex-direction: 摆放方向 */
  /*row为横 正向 默认*/
  /*row-reverse为横 逆向*/
  /*column 列正向*/
  /*column-reverse 列逆向*/
  /* flex-direction: row; */

  /* flex-wrap: 是否换行 */
  /*默认不换行,wrap当元素在同一行挤不下去自动换到下一行,wrap-reverse逆向换行*/
  /* flex-wrap: wrap-reverse; */
 
  /* justify-content:对齐方式 */

  /* flex-start:左对齐*/
  /* flex-end:右对齐*/
  /* center:中间对齐*/
  /* space-around:环绕对齐,每个元素周围都有间隔*/
  /* space-between:只在两个元素之间有间隔*/

  /* justify-content: space-between; */
}
.size{
  height: 150rpx;
  width: 150rpx;
}

.a{
  background-color: red;
  order: 1;
  /*占2/7宽*/
  flex: 2;
}

.b{
  background-color: yellow;
  order: 11;
   flex: 1;
}

.c{
  background-color: blue;
  order: 10;
   flex: 2;
}

.d{
  background-color: blueviolet;
  order: 3;
   flex: 1;
}

.e{
  background-color: orange;
  order: 2;
   flex: 1;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值