flex布局-实现弹性元素的各种排列

骰子布局样式

单个点

flex容器

.flex-container{
            width: 400px;
            height: 400px;
            background-color: deepskyblue; 
            
            display: flex; /*将盒子变成弹性容器*/
}
<div class="flex-container">
        <div class="flex-items"></div>
    </div>

1.左上

左上

  1. 主轴为横轴
/*左上是默认样式,弹性容器不用再添加其他属性*/
  1. 主轴为纵轴
flex-direction: column;

2.左中

左中

  1. 主轴为横轴
 justify-content: center;
  1. 主轴为纵轴
flex-direction: column;
align-items: center;

3.右上

右上

  1. 主轴为横轴
 justify-content: flex-end;
  1. 主轴为纵轴
 flex-direction: column;
 align-items: flex-end;

4.左中

左中

  1. 主轴为横轴
align-items: center;
  1. 主轴为纵轴
 flex-direction: column;
 justify-content: center;

5.中中

中中

  1. 主轴为横轴
 justify-content: center;
 align-items: center;
  1. 主轴为纵轴
 flex-direction: column;
 justify-content: center;
 align-items: center;

6.右中

右中

  1. 主轴为横轴
 justify-content: flex-end;
 align-items: center;
  1. 主轴为纵轴
 flex-direction: column;
 justify-content: center;
 align-items: flex-end;

7.左下

左下

  1. 主轴为横轴
 align-items: flex-end;
  1. 主轴为纵轴
 flex-direction: column;
 justify-content: flex-end;

8.中下

中下

  1. 主轴为横轴
 justify-content: center;
 align-items: flex-end;
  1. 主轴为纵轴
 flex-direction: column;
 justify-content: flex-end;
 align-items: center;

9.右下

在这里插入图片描述

  1. 主轴为横轴
 justify-content: flex-end;
 align-items: flex-end;
  1. 主轴为纵轴
 flex-direction: column;
 justify-content: flex-end;
 align-items: flex-end;

两个点

flex容器

.flex-container{
            width: 400px;
            height: 400px;
            background-color: deepskyblue; 
            
            display: flex; /*将盒子变成弹性容器*/
}
<div class="flex-container">
        <div class="flex-items"></div>
        <div class="flex-items"></div>
    </div>

1.左上,右上

在这里插入图片描述

  1. 主轴为横轴

弹性父元素的css样式

justify-content: space-between;

2.左上,左下

在这里插入图片描述

  1. 主轴为纵轴

弹性父元素的css样式

 flex-direction: column;
 justify-content: space-between;

3.左下,右下

左下,右下

  1. 主轴为横轴

弹性父元素的css样式

 justify-content: space-between;
  align-items: flex-end;

4.左上,右下

左上,右下

  1. 主轴为纵轴

弹性父元素的css样式

flex-direction: column;
 justify-content: space-between;
 align-items: flex-end;

5.中上,中下

中上,中下
2. 主轴为纵轴

弹性父元素的css样式

 flex-direction: column;
 justify-content: space-between;
 align-items: center;

6.对角1

对角1

  1. 主轴为横轴

弹性子元素的css样式

.flex-items:nth-child(2){
 align-self: center;
}
  1. 主轴为纵轴

弹性父元素的css样式

flex-direction: column;

弹性子元素的css样式

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

7.对角2

对角2

  1. 主轴为横轴

弹性父元素的css样式

justify-content: space-between;

弹性子元素的css样式

.flex-items:nth-child(2){
 align-self: flex-end;
}
  1. 主轴为纵轴

弹性父元素的css样式

flex-direction: column;
justify-content: space-between;

弹性子元素的css样式

.flex-items:nth-child(2){
 align-self: flex-end;
}

三个点

<div class="box">
        <div class="column"></div>
        <div class="column"></div>
        <div class="column"></div>
    </div>

1.对角

在这里插入图片描述

  1. 主轴为横轴

弹性子元素的css样式

.flex-items:nth-child(2){
      align-self: center;
}
.flex-items:nth-child(3){
       align-self: flex-end;
}
  1. 主轴为纵轴

弹性父元素的css样式

flex-direction: column;

弹性子元素的css样式

.flex-items:nth-child(2){
      align-self: center;
}
.flex-items:nth-child(3){
       align-self: flex-end;
}

四个点

1.四角

四角

<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 {
            width: 400px;
            height: 400px;
            background-color: deepskyblue;
			display: flex;
			flex-wrap: wrap;
			align-content: space-between;
  }

.column {
            flex-basis: 100%;
            display: flex;
            justify-content: space-between;
}

.item{
            width: 100px;
            height: 100px;
            background-color: chartreuse;
 }

五个点

对角5

<div class="box">
        <div class="column">
          <span class="item"></span>
          <span class="item"></span>
        </div>
        <div class="column items">
          <span class="item "></span>
        </div>
        <div class="column">
          <span class="item"></span>
          <span class="item"></span>
        </div>
      </div>

.box {
            width: 400px;
            height: 400px;
            background-color: deepskyblue;
            display: flex;
            flex-wrap: wrap;
            align-content: space-between;
        }

.column {
            flex-basis: 100%;
            display: flex;
            justify-content: space-between;
        }

.item{
            width: 100px;
            height: 100px;
            background-color: chartreuse;
        }
.items{
            justify-content:center;
        }

六个点

flex容器

两种情况的css样式是一样的,只是在html上有一一点点差别。

弹性父元素的css样式

.flex-container{
            width: 400px;
            height: 400px;
            background-color: deepskyblue;
            
            display: flex;
            flex-wrap: wrap;
            align-content: space-between;
            
        }

弹性子元素的css样式


        .flex-items{
            flex-basis: 100%;
            display: flex;
            justify-content: space-between;
            
        }   
        .item{
            width: 100px;
           height: 100px;
            background-color: chartreuse;
        }

1.左右各3

左右各3

<div class="flex-container">
        <div class="flex-items">
            <div class="item"></div>
            <div class="item"></div>
        </div>
        <div class="flex-items">
            <div class="item"></div>
            <div class="item"></div>
        </div>
        <div class="flex-items">
            <div class="item"></div>
            <div class="item"></div>
        </div>
    </div>

2.上下各3

上下各3

<div class="flex-container">
        <div class="flex-items">
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
        </div>
        <div class="flex-items">
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
        </div>
 </div>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值