如何修复css中旋转轮的选择一个堆叠在另一个顶部?

az31mfrm  于 2023-03-24  发布在  其他
关注(0)|答案(1)|浏览(165)

我已经试着让这个旋转的轮子工作了几天了,我仍然有麻烦!CSS代码导致问题,轮子应该显示八个等距的形状,每个形状上都有文本。它没有。
三个可能的结果或选择是在适当的区域,大小正确,并有正确的文字,但在这三个选择在圆圈中,它去了八个结果的第四个。第四个是正确的大小和形状,但五,六,七,八都堆叠在四个在不同的方向和大小的顶部。此外,文字四,五,六,七,八,只在某些地方显示,如果有的话

@import url('https://fonts.googleapis.com/css?family=Poppins:200,300,400,500,600,700,800,900&display=snap');
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Poppins', sans-serif;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: #333;
}

.container {
  position: relative;
  width: 400px;
  height: 400px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container .spinBtn {
  position: absolute;
  width: 60px;
  height: 60px;
  background: #fff;
  border-radius: 50%;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  text-transform: uppercase;
  font-weight: 600;
  color: #333;
  letter-spacing: 0.1em;
  border: 4px solid rgba(0, 0, 0, 0.75);
  cursor: pointer;
  user-select: none;
}

.container .spinBtn::before {
  content: '';
  position: absolute;
  top: -28px;
  width: 20px;
  height: 30px;
  background: #fff;
  clip-path: polygon(50% 0%, 15% 100%, 85% 100%);
}

.container .wheel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #333;
  overflow: hidden;
  border-radius: 50%;
  box-shadow: 0 0 0 5px #333, 0 0 0 15px #fff, 0 0 0 18px #111;
}

.container .wheel .number {
  position: absolute;
  width: 50%;
  height: 50%;
  background: var(--clr);
  transform-origin: bottom right;
  transform: rotate(calc(45deg * var(--i)));
  clip-path: polygon(0 0, 56% 0, 100% 100%, 0 56%);
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
  cursor: pointer;
}
<div class="container">
  <div class="spinBtn">Spin</div>
  <div class="wheel">
    <div class="number" style="--i:1;--clr:#db7093;"><span>Bite Release</span></div>
    <div class="number" style="--i:2;--clr:#20b2aa;"><span>Front Choke Release</span></div>
    <div class="number" style="--i:3;--clr:#d63e92;"><span>Stripping a Grab</span></div>
    <div class="number" style="--i:4;--clr:#daa520;"><span>Wrist Release</span>
      <div class="number" style="--i:5;--clr:#ff340f;"><span>Shoulder Check</span></div>
      <div class="number" style="--i:6;--clr:#ff7f50;"><span>Protective Shuffle</span></div>
      <div class="number" style="--i:7;--clr:#3cb371;"><span>Safety Stance</span></div>
      <div class="number" style="--i:8;--clr:#4169e1;"><span>Elbow Check</span></div>
    </div>
  </div>

我为它做了一个CodePen,你可以在这里查看:CodePen.io
我还应该提一下我正在关注YouTube教程,我在7:36遇到问题。链接是here

krcsximq

krcsximq1#

你有代表第五、六、七和八部分的div,它们都在代表第四部分的div中。一旦你把它们移出来,它就可以工作了。这就是主体中的代码应该看起来的样子:

<body>
  <div class="container">
    <div class="spinBtn">Spin</div>
    <div class="wheel">
      <div class="number" style="--i:1;--clr:#db7093;"><span>Bite Release</span></div>
      <div class="number" style="--i:2;--clr:#20b2aa;"><span>Front Choke Release</span></div>
      <div class="number" style="--i:3;--clr:#d63e92;"><span>Stripping a Grab</span></div>
      <div class="number" style="--i:4;--clr:#daa520;"><span>Wrist Release</span></div>
      <div class="number" style="--i:5;--clr:#ff340f;"><span>Shoulder Check</span></div>
      <div class="number" style="--i:6;--clr:#ff7f50;"><span>Protective Shuffle</span></div>
      <div class="number" style="--i:7;--clr:#3cb371;"><span>Safety Stance</span></div>
      <div class="number" style="--i:8;--clr:#4169e1;"><span>Elbow Check</span></div>
    </div>
</body>

相关问题