flex布局:骰子

1 篇文章 0 订阅
这篇博客展示了如何利用CSS的Flex布局来实现一个骰子的六面显示。通过调整不同面的点数布局,实现了从1到6的点数分布,包括水平和垂直排列的点。代码中详细定义了每个面的样式和点的位置,提供了一个直观的前端开发示例。
摘要由CSDN通过智能技术生成

flex布局实现骰子的六个面

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>flex骰子</title>
  <style>
    *{
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    .touzi{
      margin: 100px auto;
      width: 1000px;
      height: 150px;
      display: flex;
      justify-content: space-between
    }
    /* 面 */
    .box{
      display: flex;
      padding: 10px;
      width: 150px;
      height: 150px;
      background-color: #e7e7e7;
      border-radius: 10px;
      box-shadow: inset 0 5px white,inset 0 -5px #bbb,inset 5px 0 #d7d7d7,inset -5px 0 #d7d7d7;
    }
    /* 点 */
    span{
      display: inline-block;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background-color: black;
      box-shadow: inset 0 -2px #bbb;
    }
    /* 点数1 */
    .one{
      justify-content: center;
      align-items: center;

    }
    /* 点数2 */
    .two{
      justify-content: space-between;
    }
    .two span:last-child{
      align-self: flex-end;
    }
    /* 点数3 */
    .three{
      justify-content: space-between;
    }
    .three span:nth-child(2){
      align-self: center;
    }
    .three span:last-child{
      align-self: flex-end;
    }
    /* 点数4 */
    .four{
      flex-direction: column;
      justify-content: space-between;
    }
    .four div{
      display: flex;
      justify-content: space-between;
    }
    /* 点数5 */
    .five{
      flex-direction: column;
      justify-content: space-between;
    }
    .five div{
      display: flex;
      justify-content: space-between;
    }
    .center{
      align-self: center;
    }

    /* 点数6 */
    .six{
      flex-direction: column;
      justify-content: space-between;
    }
    .six div{
      display: flex;
      justify-content: space-between;
    }

  </style>
</head>
<body>
  <div class="touzi">
    <div class="box one">
      <span></span>
    </div>
    <div class="box two">
      <span></span><span></span>
    </div>
    <div class="box three">
      <span></span><span></span><span></span>
    </div>
    <div class="box four">
      <div>
        <span></span><span></span>
      </div>
      <div>
        <span></span><span></span>
      </div>
    </div>
    <div class="box five">
      <div>
        <span></span><span></span>
      </div>
      <span class="center"></span>
      <div>
        <span></span><span></span>
      </div>
    </div>
    <div class="box six">
      <div>
        <span></span><span></span>
      </div>
      <div>
        <span></span><span></span>
      </div>
      <div>
        <span></span><span></span>
      </div>

    </div>
  </div>
  
</body>
</html>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值