flex弹性布局

//布局格式
<div class="box">
  <span class="item"></span>
</div>

1.基础的左对齐:只需要父元素设置flex属性即可 排列由左往右排

.box {
  display: flex;
}
image.png

2.设置项目的对齐方式,就能实现居中对齐 justify-content 控制X轴方向的位置

.box {
  display: flex;
  justify-content: center;
}
image.png

3.设置项目的对齐方式,就能实现居右对起

.box {
  display: flex;
  justify-content: flex-end;
}
image.png

4.设置交叉轴对齐方式,可以垂直移动主轴。

.box {
  display: flex;
  align-items: center;
}
image.png
.box {
  display: flex;
  justify-content: center;
  align-items: center;
}
image.png
.box {
  display: flex;
  justify-content: center;
  align-items: flex-end;
}
image.png
.box {
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
}
image.png
.box {
  display: flex;
  justify-content: space-between;
}
image.png
.box {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
image.png
.box {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}
image.png
.box {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-end;
}
image.png
.box {
  display: flex;
}

.item:nth-child(2) {
  align-self: center;
}
image.png
.box {
  display: flex;
  justify-content: space-between;
}

.item:nth-child(2) {
  align-self: flex-end;
}
image.png
.box {
  display: flex;
}

.item:nth-child(2) {
  align-self: center;
}

.item:nth-child(3) {
  align-self: flex-end;
}
image.png
.box {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-content: space-between;
}
image.png
<div class="box">
  <div class="column">
    <span class="item"></span>
    <span class="item"></span>
  </div>
  <div class="column">
    <span class="item"></span>
    <span class="item"></span>
  </div>
</div>
.box {
  display: flex;
  flex-wrap: wrap;
  align-content: space-between;
}

.column {
  flex-basis: 100%;
  display: flex;
  justify-content: space-between;
}
image.png
<div class="box">
  <div class="row">
    <span class="item"></span>
    <span class="item"></span>
    <span class="item"></span>
  </div>
  <div class="row">
    <span class="item"></span>
  </div>
  <div class="row">
     <span class="item"></span>
     <span class="item"></span>
  </div>
</div>
.box {
  display: flex;
  flex-wrap: wrap;
}

.row{
  flex-basis: 100%;
  display:flex;
}

.row:nth-child(2){
  justify-content: center;
}

.row:nth-child(3){
  justify-content: space-between;
}

`

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

推荐阅读更多精彩内容

  • 作者: 阮一峰日期: 2015年7月10日原文链接:http://www.ruanyifeng.com/blog/...
    Mike_Gu阅读 1,000评论 0 6
  • 2009年,W3C 提出了一种新的方案----Flex 布局,可以简便、完整、响应式地实现各种页面布局。目前,它已...
    Dr老爹阅读 375评论 0 1
  • Flex是Flexible Box的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性。设为Flex布局以后,...
    xiaotao123阅读 1,760评论 0 1
  • 推荐学习文档:http://www.ruanyifeng.com/blog/2015/07/flex-gramma...
    BULL_DEBUG阅读 382评论 0 0
  • 伸缩容器的属性 display: flex 定义为弹性布局 flex-direction 决定主轴的方向 flex...
    浅夏_cd06阅读 817评论 0 0