Sass / CSS色轮

问题描述 投票:0回答:1

我制作了一个色轮,除了最后一个元素占用更多空间且它的width较大之外,它看起来不错。我怎样才能使我所有的span's都具有相等的宽度

demo

@for $i from 1 through 25 {
  span:nth-child(#{$i}) {
    border-top-color: hsl($i * 15, 50%, 50%);
    border-left-color: transparent;
    border-right-color: transparent;
    border-bottom-color: transparent;
  }
}

@for $i from 1 through 25 {
  span:nth-child(#{$i}) {
    transform: rotate($i * 14.4deg);
  }
}

#colorWheel {
  -webkit-animation: intro 3s ease;
  width: 100px;
  height: 100px;
  margin: 0 auto;
  position: relative;
  transform-origin: 50px 150px;
  transition: all 0.5s linear;
}

#colorWheel::before {
  content: "";
  width: 300px;
  height: 300px;
  overflow: hidden;
  position: absolute;
  top: -30px;
  left: -130px;
  border-radius: 100%;
  border: 30px solid #ffffff;
  z-index: 100;
}

#colorWheel span {
  position: absolute;
  -webkit-transform-origin: 50% 50%;
  border-style: solid;
  border-width: 150px 50px;
  box-sizing: border-box;
}
<div id="colorWheel">
    <span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span> <!-- 25 span's -->
  </div>
html css sass
1个回答
0
投票

这里是基于this previous answer的代码的优化:

@for $i from 1 through 25 {
  span:nth-child(#{$i}) {
    background-color: hsl($i * 15, 50%, 50%);
  }
}

@for $i from 1 through 25 {
  span:nth-child(#{$i}) {
    transform: rotate($i * 14.4deg);
  }
}

#colorWheel {
  height: 300px;
  width: 300px;
  position:relative;
  display:block;
  margin:auto;
}
#colorWheel > * {
  position:absolute;
  top:0;
  left:0;
  right:0;
  bottom:0;
  border-radius:50%;
  clip-path:polygon(
    50% 50%, 
    50% 0%, 
    63% 0%); 
}

演示:https://jsfiddle.net/zduv6qw3/1/

编译的CSS:

span:nth-child(1) {
  background-color: #bf6040;
}

span:nth-child(2) {
  background-color: #bf8040;
}

span:nth-child(3) {
  background-color: #bf9f40;
}

span:nth-child(4) {
  background-color: #bfbf40;
}

span:nth-child(5) {
  background-color: #9fbf40;
}

span:nth-child(6) {
  background-color: #80bf40;
}

span:nth-child(7) {
  background-color: #60bf40;
}

span:nth-child(8) {
  background-color: #40bf40;
}

span:nth-child(9) {
  background-color: #40bf60;
}

span:nth-child(10) {
  background-color: #40bf80;
}

span:nth-child(11) {
  background-color: #40bf9f;
}

span:nth-child(12) {
  background-color: #40bfbf;
}

span:nth-child(13) {
  background-color: #409fbf;
}

span:nth-child(14) {
  background-color: #4080bf;
}

span:nth-child(15) {
  background-color: #4060bf;
}

span:nth-child(16) {
  background-color: #4040bf;
}

span:nth-child(17) {
  background-color: #6040bf;
}

span:nth-child(18) {
  background-color: #8040bf;
}

span:nth-child(19) {
  background-color: #9f40bf;
}

span:nth-child(20) {
  background-color: #bf40bf;
}

span:nth-child(21) {
  background-color: #bf409f;
}

span:nth-child(22) {
  background-color: #bf4080;
}

span:nth-child(23) {
  background-color: #bf4060;
}

span:nth-child(24) {
  background-color: #bf4040;
}

span:nth-child(25) {
  background-color: #bf6040;
}

span:nth-child(1) {
  transform: rotate(14.4deg);
}

span:nth-child(2) {
  transform: rotate(28.8deg);
}

span:nth-child(3) {
  transform: rotate(43.2deg);
}

span:nth-child(4) {
  transform: rotate(57.6deg);
}

span:nth-child(5) {
  transform: rotate(72deg);
}

span:nth-child(6) {
  transform: rotate(86.4deg);
}

span:nth-child(7) {
  transform: rotate(100.8deg);
}

span:nth-child(8) {
  transform: rotate(115.2deg);
}

span:nth-child(9) {
  transform: rotate(129.6deg);
}

span:nth-child(10) {
  transform: rotate(144deg);
}

span:nth-child(11) {
  transform: rotate(158.4deg);
}

span:nth-child(12) {
  transform: rotate(172.8deg);
}

span:nth-child(13) {
  transform: rotate(187.2deg);
}

span:nth-child(14) {
  transform: rotate(201.6deg);
}

span:nth-child(15) {
  transform: rotate(216deg);
}

span:nth-child(16) {
  transform: rotate(230.4deg);
}

span:nth-child(17) {
  transform: rotate(244.8deg);
}

span:nth-child(18) {
  transform: rotate(259.2deg);
}

span:nth-child(19) {
  transform: rotate(273.6deg);
}

span:nth-child(20) {
  transform: rotate(288deg);
}

span:nth-child(21) {
  transform: rotate(302.4deg);
}

span:nth-child(22) {
  transform: rotate(316.8deg);
}

span:nth-child(23) {
  transform: rotate(331.2deg);
}

span:nth-child(24) {
  transform: rotate(345.6deg);
}

span:nth-child(25) {
  transform: rotate(360deg);
}

#colorWheel {
  height: 300px;
  width: 300px;
  position: relative;
  display: block;
  margin:auto;
}

#colorWheel > * {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 50%;
  clip-path: polygon(50% 50%, 50% 0%, 63% 0%);
}
<div id="colorWheel">
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
  </div>
© www.soinside.com 2019 - 2024. All rights reserved.