css3画立体图形

一,效果

在这里插入图片描述

二,代码

<template>
  <div id="app">
    <div>
      <div class="yuanzhui">
        <div></div>
      </div>
    </div>
    <div class="cube">
      <div class="side front"></div>
      <div class="side back"></div>
      <div class="side right"></div>
      <div class="side left"></div>
      <div class="side top"></div>
    </div>

    <div class="cube2">
      <div class="side front"></div>
      <div class="side back"></div>
      <div class="side right"></div>
      <div class="side left"></div>
      <div class="side top"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: "App",
  components: {},
  data() {
    return {};
  },
  methods: {},
};
</script>

<style scoped lang="scss">
.yuanzhui {
  margin: auto;
  position: relative;
  width: 200px;
  height: 300px;
  // background: red;
  &::before {
    position: absolute;
    content: "";
    left: 0px;
    width: 0;
    height: 0;
    border-bottom: 120px solid rgba(255, 103, 116, 0.8);
    border-left: 100px solid transparent;
    border-top: 170px solid transparent;
    transform: skewY(10deg);
    filter: drop-shadow(3px 3px 5px rgba(241, 198, 241, 0.5));
  }
  &:after {
    position: absolute;
    content: "";
    right: 0px;
    width: 0;
    height: 0;
    border-bottom: 120px solid rgba(255, 103, 116, 0.8);
    border-right: 100px solid transparent;
    border-top: 170px solid transparent;
    transform: skewY(-10deg);
    filter: drop-shadow(6px 6px 5px rgba(241, 198, 241, 0.5));
  }
  div {
    position: absolute;
    bottom: 2px;
    left: 98px;
    width: 4px;
    height: 120px;
    background: #fff;
    z-index: 9;
    opacity: 0.3;
    box-shadow: 0px -2px 4px 1px #fff;
  }
}

.cube {
  position: relative;
  top: 30px;
  width: 400px;
  height: 5px;
  // background: red;
  margin: auto;
  transform-style: preserve-3d;
  transform: rotateX(-10deg) rotateY(45deg);
  transform-origin: center;
  height: 2px;
  .side {
    position: absolute;
    width: 200px;
    height: 200px;
    background: transparent;
    // border: 1px solid rgba(0, 0, 0, 0.5);
    color: white;
  }
  .front {
    transform-origin: top;
    transform: translateZ(100px) rotateX(30deg);
    width: 200px;
    height: 0;
    border-bottom: 200px solid rgba(247, 67, 226, 0.8);
    border-left: 100px solid transparent;
    border-right: 100px solid transparent;
    filter: drop-shadow(3px 3px 5px rgba(0, 0, 0, 0.5));
  }
  .top {
    transform: rotateX(90deg) translateZ(100px) translateX(100px);
    background: rgba(247, 67, 226, 0.8);
  }
  .left {
    transform-origin: top;
    transform: translateX(-100px) rotateY(-90deg) rotateX(30deg);
    width: 200px;
    height: 0;
    border-bottom: 200px solid rgba(247, 67, 226, 0.8);
    border-top: 0 solid transparent;
    border-left: 100px solid transparent;
    border-right: 100px solid transparent;
    filter: drop-shadow(3px 3px 5px rgba(0, 0, 0, 0.5));
  }
  .right {
    transform-origin: top;
    transform: translateX(100px) rotateY(90deg) rotateX(30deg);
    width: 200px;
    height: 0;
    border-bottom: 200px solid rgba(247, 67, 226, 0.8);
    border-top: 0 solid transparent;
    border-left: 100px solid transparent;
    border-right: 100px solid transparent;
    filter: drop-shadow(3px 3px 5px rgba(0, 0, 0, 0.5));
  }
  .back {
    transform-origin: top;
    transform: translateZ(-100px) rotateX(-30deg);
    width: 200px;
    height: 0;
    border-bottom: 200px solid rgba(247, 67, 226, 0.8);
    border-top: 0 solid transparent;
    border-left: 100px solid transparent;
    border-right: 100px solid transparent;
    filter: drop-shadow(3px 3px 5px rgba(0, 0, 0, 0.5));
  }
}

.cube2 {
  position: relative;
  top: 300px;
  width: 800px;
  height: 5px;
  margin: auto;
  transform-style: preserve-3d;
  transform: rotateX(-10deg) rotateY(45deg);
  transform-origin: center;
  .side {
    position: absolute;
    width: 400px;
    height: 400px;
    background: transparent;
    // border: 1px solid rgba(0, 0, 0, 0.5);
    color: white;
  }
  .front {
    transform-origin: top;
    transform: translateZ(200px) rotateX(30deg);
    width: 400px;
    height: 0;
    border-bottom: 400px solid rgba(30, 119, 252, 0.8);
    border-left: 200px solid transparent;
    border-right: 200px solid transparent;
    filter: drop-shadow(3px 3px 5px rgba(0, 0, 0, 0.5));
  }
  .top {
    transform: rotateX(90deg) translateZ(100px) translateX(200px);
    background: rgba(15, 89, 201, 0.8);
  }
  .left {
    transform-origin: top;
    transform: translateX(-200px) rotateY(-90deg) rotateX(30deg);
    width: 400px;
    height: 0;
    border-bottom: 400px solid rgba(30, 119, 252, 0.8);
    border-top: 0 solid transparent;
    border-left: 200px solid transparent;
    border-right: 200px solid transparent;
    filter: drop-shadow(3px 3px 5px rgba(0, 0, 0, 0.5));
  }
  .right {
    transform-origin: top;
    transform: translateX(200px) rotateY(90deg) rotateX(30deg);
    width: 400px;
    height: 0;
    border-bottom: 400px solid rgba(30, 119, 252, 0.8);
    border-top: 0 solid transparent;
    border-left: 200px solid transparent;
    border-right: 200px solid transparent;
    filter: drop-shadow(3px 3px 5px rgba(0, 0, 0, 0.5));
  }
  .back {
    transform-origin: top;
    transform: translateZ(-200px) rotateX(-30deg);
    width: 400px;
    height: 0;
    border-bottom: 400px solid rgba(30, 119, 252, 0.8);
    border-top: 0 solid transparent;
    border-left: 200px solid transparent;
    border-right: 200px solid transparent;
    filter: drop-shadow(3px 3px 5px rgba(0, 0, 0, 0.5));
  }
}
</style>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值