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>
相关推荐
engchina38 分钟前
@media 的常用场景与示例
css·media
林的快手1 小时前
CSS列表属性
前端·javascript·css·ajax·firefox·html5·safari
匹马夕阳1 小时前
ECharts极简入门
前端·信息可视化·echarts
API_technology2 小时前
电商API安全防护:JWT令牌与XSS防御实战
前端·安全·xss
yqcoder2 小时前
Express + MongoDB 实现在筛选时间段中用户名的模糊查询
java·前端·javascript
十八朵郁金香2 小时前
通俗易懂的DOM1级标准介绍
开发语言·前端·javascript
m0_528723813 小时前
HTML中,title和h1标签的区别是什么?
前端·html
Dark_programmer3 小时前
html - - - - - modal弹窗出现时,页面怎么能限制滚动
前端·html
GDAL3 小时前
HTML Canvas clip 深入全面讲解
前端·javascript·canvas
禾苗种树3 小时前
在 Vue 3 中使用 ECharts 制作多 Y 轴折线图时,若希望 **Y 轴颜色自动匹配折线颜色**且无需手动干预,可以通过以下步骤实现:
前端·vue.js·echarts