CSS 用 flex 布局绘制骰子

html 复制代码
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      .box {
        height: 100px;
        width: 100px;
        border: 2px solid grey;
        border-radius: 10px;
        display: flex;
        justify-content: center; // 水平居中
        /* align-items: center; */
      }

      .point {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: black;
        /* align-self 写在子元素上,覆盖父元素指定的交叉轴对齐方式 */
        align-self: center;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="point"></div>
    </div>
  </body>
</html>
html 复制代码
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      .box {
        height: 100px;
        width: 100px;
        border: 2px solid grey;
        border-radius: 10px;
        display: flex;
        /* 主轴改为纵向  */
        flex-direction: column;
        /* 等分 */
        justify-content: space-evenly;
        /* 垂直居中 */
        align-items: center;
      }

      .point {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: black;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="point"></div>
      <div class="point"></div>
    </div>
  </body>
</html>
html 复制代码
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      .box {
        height: 100px;
        width: 100px;
        border: 2px solid grey;
        border-radius: 10px;
        display: flex;
        padding: 10px;
        /* 主轴改为纵向  */
        flex-direction: column;
        /* 子元素间距相等*/
        justify-content: space-between;
      }

      .point {
        width: 25px;
        height: 25px;
        border-radius: 50%;
        background: black;
      }

      .point:nth-child(2) {
        /* 居中对齐 */
        align-self: center;
      }

      .point:nth-child(3) {
        /* 终点对齐 */
        align-self: flex-end;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="point"></div>
      <div class="point"></div>
      <div class="point"></div>
    </div>
  </body>
</html>
html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title></title>
    <style>
      .box {
        margin: 20px;
        height: 100px;
        width: 100px;
        border: 2px solid grey;
        border-radius: 10px;
        padding: 10px;
        box-sizing: border-box;

        display: flex;
        /* 纵向 */
        flex-wrap: wrap;
        /* 相对均匀对齐  */
        align-content: space-between;
      }

      .row {
        /* 空间大小 */
        flex-basis: 100%;
        display: flex;
        justify-content: space-between
      }

      .point {
        border-radius: 50%;
        height: 25px;
        width: 25px;
        background: black;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="row">
        <div class="point"></div>
        <div class="point"></div>
      </div>
      <div class="row">
        <div class="point"></div>
        <div class="point"></div>
      </div>
    </div>
  </body>
</html>
html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title></title>
    <style>
      .box {
        margin: 20px;
        height: 100px;
        width: 100px;
        border: 2px solid grey;
        border-radius: 10px;
        padding: 10px;
        box-sizing: border-box;

        /* 容器内元素使用flex布局 */
        display: flex;
        /* 将主轴改为纵向 */
        flex-direction: column;
        /* 主轴(纵向)绝对均匀对齐(子元素间距以及两端边缘间距都相等) */
        justify-content: space-evenly;
      }

      .row1 {
        /* 每行内元素使用flex布局 */
        display: flex;
        /* 主轴(横向)相对均匀对齐 */
        justify-content: space-between;
      }

      .row2 {
        /* 每行内元素使用flex布局 */
        display: flex;
        /* 主轴(横向)居中对齐 */
        justify-content: center;
      }

      .point {
        border-radius: 50%;
        height: 25px;
        width: 25px;
        background: black;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="row1">
        <div class="point"></div>
        <div class="point"></div>
      </div>
      <div class="row2">
        <div class="point"></div>
      </div>
      <div class="row1">
        <div class="point"></div>
        <div class="point"></div>
      </div>
    </div>
  </body>
</html>
html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title></title>
    <style>
      .box {
        margin: 20px;
        height: 100px;
        width: 100px;
        border: 2px solid grey;
        border-radius: 10px;
        padding: 10px;
        box-sizing: border-box;

        /* 容器内元素使用flex布局 */
        display: flex;
        /* 将主轴改为纵向 */
        flex-direction: column;
        /* 主轴(纵向)相对均匀对齐 */
        justify-content: space-between;
      }

      .row {
        /* 每行内元素使用flex布局 */
        display: flex;
        /* 主轴(横向)绝对均匀对齐 */
        justify-content: space-evenly;
      }

      .point {
        border-radius: 50%;
        height: 20px;
        width: 20px;
        background: black;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="row">
        <div class="point"></div>
        <div class="point"></div>
        <div class="point"></div>
      </div>
      <div class="row">
        <div class="point"></div>
        <div class="point"></div>
        <div class="point"></div>
      </div>
      <div class="row">
        <div class="point"></div>
        <div class="point"></div>
        <div class="point"></div>
      </div>
    </div>
  </body>
</html>
相关推荐
哟哟耶耶几秒前
js-将JavaScript对象或值转换为JSON字符串 JSON.stringify(this.SelectDataListCourse)
前端·javascript·json
getaxiosluo1 分钟前
react jsx基本语法,脚手架,父子传参,refs等详解
前端·vue.js·react.js·前端框架·hook·jsx
理想不理想v4 分钟前
vue种ref跟reactive的区别?
前端·javascript·vue.js·webpack·前端框架·node.js·ecmascript
知孤云出岫5 分钟前
web 渗透学习指南——初学者防入狱篇
前端·网络安全·渗透·web
贩卖纯净水.10 分钟前
Chrome调试工具(查看CSS属性)
前端·chrome
栈老师不回家1 小时前
Vue 计算属性和监听器
前端·javascript·vue.js
前端啊龙1 小时前
用vue3封装丶高仿element-plus里面的日期联级选择器,日期选择器
前端·javascript·vue.js
一颗松鼠1 小时前
JavaScript 闭包是什么?简单到看完就理解!
开发语言·前端·javascript·ecmascript
小远yyds2 小时前
前端Web用户 token 持久化
开发语言·前端·javascript·vue.js
吕彬-前端2 小时前
使用vite+react+ts+Ant Design开发后台管理项目(五)
前端·javascript·react.js