html交叉轴排列,CSS Flex 交叉轴水平方向

交叉轴是垂直方向还是水平方向,需要根据主轴方向(flex-direction: column),如果主轴是水平方向那么交叉轴为垂直方向,如果主轴方向垂直方向(flex-direction: column),交叉轴就是水平方向。

1. align-items: flex-start

主轴为垂直排列那么交叉轴就是水平方向

flex-direction: column;

align-items: flex-start;

05221d380684

Jietu20191229-204126.jpg

2. align-items:flex-end

主轴横向排列交叉轴为纵向排列,那么flex-end 就是交叉轴下方是排列结束位置

article {

display: flex;

border: solid 5px silver;

border-color: #8A2BE2;

width: 450px;

height: 280px;

background: red;

flex-direction: column;

align-items: flex-end;

}

05221d380684

主轴横向.jpg

3. align-items: center

主轴是水平横向排列,那么交叉轴为垂直方向纵向排列 center 就是交叉轴中心位置对齐

article {

display: flex;

border: solid 5px silver;

border-color: #8A2BE2;

width: 450px;

height: 280px;

background: red;

flex-direction: row;

align-items: center;

}

05221d380684

Jietu20191229-194450.jpg

4. align-items: stretch

主轴是水平横向排列,那么交叉轴为垂直方向纵向排列 stretch 会沿着交叉轴垂直方向拉伸填充完垂直方向容器 注意必须是容器内的子元素没有设置垂直方向高度,设置尺寸则该元素属性无法生效

article {

display: flex;

border: solid 5px silver;

border-color: #8A2BE2;

width: 450px;

height: 280px;

background: red;

flex-direction: row;

align-items: stretch;

}

article * {

width: 100px;

/* height: 100px; */

}

05221d380684

Jietu20191229-195349.jpg

测试代码

* {

padding: 0px;

margin: 0px;

}

body {

padding-left: 0px;

padding-top: 15px;

}

article {

display: flex;

border: solid 5px silver;

border-color: #8A2BE2;

width: 450px;

height: 280px;

background: red;

flex-direction: row;

align-items: flex-end;

}

article * {

width: 100px;

height: 100px;

}

.first {

background: #87CEEB;

}

.second {

background: #FFA07A;

}

.third {

background: lightpink;

}

.fourth {

background: lightgreen;

}

第一
第二
第三
第四
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值