Flex布局实例-骰子布局

1、 单项目

首先,只有左上角有1个点的情况。Flex布局默认就是首行左对齐,所以一行代码就够啦。

左上角.png
.box {
    display: flex
}

设置项目的对齐方式,就能实现居中对齐和右对齐。

水平居中.png
.box {
  display: flex;
  justify-content: center;
}

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

垂直居中.png
.box {
  display: flex;
  align-items: center;
}
水平垂直居中.png
.box {
  display: flex;
  justify-content: center;
  align-items: center;
}
水平居中底部.png
.box {
  display: flex;
  justify-content: center;
  align-items: flex-end;
}
右下角.png
.box {
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
}

2、双项目

.box {
    display: flex;
    justify-content: space-between;
}
.box {
    display: flex;
    flex-firection: column;
    justify-content: space-between;
}
.box {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
}
.box {
    display: flex;
    flex-direction: colunmn;
    justify-content: space-between;
    align-items: flex-end;
}
.box {
    display: flex;
}
.box .item:nth-child(2) {
    align-self: center;
}
.box {
    display: flex;
    justify-content: space-between;
}
.box .item:nth-child(2) {
    align-self: flex-end;
}

3、三项目

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

4、四项目

.box {
     display: flex;
     flex-wrap: wrap;
     justify-content: space-between;
     align-content: space-between;
}
html结构为:
css代码如下: .box { display: flex; flex-warp: warp; algin-content: space-between; } .box .column { flex-basis: 100%; display: flex; justify-content: space-between; }

5、六项目

.box {
    display: flex;
    flex-wrap: wrap;
    align-content: space-between;
}
.box .column {
    flex-basis: 100%;
    display: flex;
    justify-content: space-between;
}
.box {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
   align-content: space-between;
}
.box .column {
    flex-basis: 100%;
    display: inline-flex;
    flex-direction: column;
    justify-content: space-between;
}

6、九项目

html结构为:
css代码为: .box { display: flex; flex-warp: warp; justify-content: space-between; } .box .column { display: flex; flex-direction: column; justify-content: space-between; }

你可能感兴趣的:(Flex布局实例-骰子布局)