flex应用以及flex应用出现对齐问题解析

1基础

/* flex */
.flex {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
}

/* flex-direction */

.flex-direction-column {
  flex-direction: column;
}

/* justify-content */

.justify-content-start {
  justify-content: flex-start
}

.justify-content-end {
  justify-content: flex-end
}

.justify-content-center {
  justify-content: center
}

.justify-content-space-between {
  justify-content: space-between
}

.justify-content-space-around {
  justify-content: space-around
}

/* flex-1 */

.flex-1 {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  -ms-flex: 1;
  flex: 1;
}

/* align-items */

.align-items-start {
  align-items: flex-start;
}

.align-items-end {
  align-items: flex-end;
}

.align-items-center {
  align-items: center;
}

/* flex-wrap */

.flex-wrap-nowrap {
  flex-wrap: nowrap
}

.flex-wrap-wrap {
  flex-wrap: wrap
}

1.1 如何让最后一项右边对齐margin-left: auto; 垂直方向对齐方式 不同

style="align-self:flex-start"

1.2 justify-content:space-between; 解决最后一排数量不够自动向两端排列问题

方案1:父级添加after伪类法,解决最后一排数量不够两端分布的情况
 <!--加上after伪类,解决最后一排数量不够两端分布的情况-->
 <!--父类-->
  .tem-flex:after{
    content: '';
    width: 30%;
    border:1px solid transparent;
  }
  <!--子类-->
  .tem-list{
    width:30%;
    border:1px solid #ff6600;
    margin-bottom: 10px;
  }
--------------------------------------------
方案2:补位添加节点法,这种方案适用于多种排列方式。

<div class="tem-flex">
  <div class="tem-list" v-for="item in len">列表</div>
  <div class="list" v-for="item in (row-len%row)" v-if="len%row > 0"></div>
</div>

data(){
	return {
		len : 14,
		row: 4
	}
}

.tem-flex{
  display: flex;
  flex-wrap: wrap;
  justify-content:space-between;
  justify-items: center;
  text-align: justify;
}
.list{
  content: '';
  width: 20%;
  border:1px solid transparent;
  padding: 5px;
  overflow: hidden;
}
.tem-list{
  width:20%;
  border:1px solid #ff6600;
  margin-bottom: 10px;
  padding: 10px 5px;
  display: flex;
  justify-content: center;
}

1.4 flex布局设置width无效

子元素 flex: 0 0 50px;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值