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结构为:
<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>

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结构为:
<div class="box">
    <div class="column">
        <div class="circle"></div>
        <div class="circle"></div>
        <div class="circle"></div>
    </div>
    <div class="column">
        <div class="circle"></div>
        <div class="circle"></div>
        <div class="circle"></div>
    </div>
    <div class="column">
        <div class="circle"></div>
        <div class="circle"></div>
        <div class="circle"></div>
    </div>
</div>

css代码为:
.box {
    display: flex;
    flex-warp: warp;
    justify-content: space-between;
}
.box .column {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • H5移动端知识点总结 阅读目录 移动开发基本知识点 calc基本用法 box-sizing的理解及使用 理解dis...
    Mx勇阅读 4,611评论 0 26
  • 移动开发基本知识点 一.使用rem作为单位 html { font-size: 100px; } @media(m...
    横冲直撞666阅读 3,511评论 0 6
  • Flex 布局教程:语法篇一、Flex 布局是什么?二、基本概念三、容器的属性6四、项目的属性6 Flex 布局教...
    百里少龙阅读 299评论 0 0
  • flex布局基础知识 main axis(主轴): Flex容器的主轴主要用来配置Flex项目。它不一定是水平,这...
    前端小兵阅读 507评论 0 1
  • 前些日子,看到一个关于诗人的很有趣的形容,他说:“诗人是庙堂上的理想 ,驴背上的诗情。”