使用flex布局写6种骰子

使用flex布局写6种骰子🎲

效果图

在这里插入图片描述

概述说明

不使用position定位,完全靠flex进行分配位置。

在线查看

点击查看

完整代码

<template>
  <div class="content">
    <ul class="list">
      <li class="item" v-for="item in 6" :key="item">
        <aside class="line" v-for="itemJ in 3" :key="itemJ">
          <div class="dot" v-for="itemK in 2" :key="itemK"></div>
        </aside>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: "",
};
</script>

<style lang="scss" scoped>
.content {
  .list {
    width: 700px;
    height: 480px;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: repeat(3, 1fr);
    .item {
      display: flex;
      $wh: 200px;
      width: $wh;
      height: $wh;
      border-radius: 10px;
      background-color: antiquewhite;
      box-shadow: 0px 7px 18px 0px rgba(0, 0, 0, 0.21);
      .line{
        // border:1px solid #f00;
      }
      // 第一个
      &:nth-child(1) {
        justify-content: center;
        align-items: center;
        .line {
          &:not(:first-child) {
            display: none;
          }
          .dot {
            &:not(:first-child) {
              display: none;
            }
          }
        }
      }
      // 第2个
      &:nth-child(2) {
        flex-wrap: wrap;
        .line {
          display: flex;
          align-items: center;
          justify-content: space-evenly;
          width: 100%;
          &:last-child {
            display: none;
          }
          &:nth-child(1) {
            .dot:nth-child(2) {
              opacity: 0;
            }
          }
          &:nth-child(2) {
            .dot:nth-child(1) {
              opacity: 0;
            }
          }
        }
      }
      // 第3个
      &:nth-child(3) {
        flex-wrap: wrap;
        .line {
          display: flex;
          align-items: center;
          justify-content: space-evenly;
          width: 100%;
          height: 33.3333%;
          
          &:nth-child(1) {
            align-items: flex-end;
            .dot:nth-child(2) {
              opacity: 0;
            }
          }
          &:nth-child(2) {
            justify-content: center;
            .dot:nth-child(1) {
              display: none;
            }
          }
          &:nth-child(3) {
            align-items: flex-start;
            .dot:nth-child(1) {
              opacity: 0;
            }
          }
        }
      }
      // 第4个
      &:nth-child(4) {
        flex-direction: column;
        justify-content: center;
        .line {
          display: flex;
          align-items: center;
          justify-content: space-evenly;
          width: 100%;
          height: 38%;
          &:nth-child(3) {
            display: none;
          }
        }
      }
      // 第5个
      &:nth-child(5) {
        flex-direction: column;
        justify-content: center;
        .line {
          display: flex;
          align-items: center;
          justify-content: space-evenly;
          width: 100%;
          height: 24%;
          &:nth-child(1) {
            align-items: flex-end;
          }
          &:nth-child(2) {
            justify-content: center;
            .dot:nth-child(1) {
              display: none;
            }
          }
          &:nth-child(3) {
            align-items: flex-start;
          }
        }
      }
      // 第6个
      &:nth-child(6) {
        flex-direction: column;
        justify-content: center;
        .line {
          display: flex;
          align-items: center;
          justify-content: space-evenly;
          width: 100%;
          height: 26%;
        }
      }
    }
    .dot {
      $wh: 30px;
      width: $wh;
      height: $wh;
      border-radius: 9999px;
      background-color: #000;
    }
  }
}
</style>

  • 29
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值