gpt4 book ai didi

html - SASS/CSS 多色轮

转载 作者:行者123 更新时间:2023-12-04 10:30:37 26 4
gpt4 key购买 nike

我做了一个色轮,除了最后一个元素占用更多空间外,它看起来不错,而且它有一个更大的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>

最佳答案

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

$num:25;

@for $i from 1 through $num {
span:nth-child(#{$i}) {
background-color: hsl($i * 15, 50%, 50%);
transform: rotate($i * (360deg/$num));
}
}

#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%,
(50%*(1 + tan(360deg/$num))) 0%);
}

演示: https://jsfiddle.net/7patx6bn/

编译版本:

span:nth-child(1) {
background-color: #bf6040;
transform: rotate(14.4deg);
}

span:nth-child(2) {
background-color: #bf8040;
transform: rotate(28.8deg);
}

span:nth-child(3) {
background-color: #bf9f40;
transform: rotate(43.2deg);
}

span:nth-child(4) {
background-color: #bfbf40;
transform: rotate(57.6deg);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

span:nth-child(20) {
background-color: #bf40bf;
transform: rotate(288deg);
}

span:nth-child(21) {
background-color: #bf409f;
transform: rotate(302.4deg);
}

span:nth-child(22) {
background-color: #bf4080;
transform: rotate(316.8deg);
}

span:nth-child(23) {
background-color: #bf4060;
transform: rotate(331.2deg);
}

span:nth-child(24) {
background-color: #bf4040;
transform: rotate(345.6deg);
}

span:nth-child(25) {
background-color: #bf6040;
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>


CSS Multi-color wheel

考虑到您的代码,您需要为 border-width 设置值您不会有任何重叠的地方: https://jsfiddle.net/zduv6qw3/2/

更新了 border-width150px 18.8pxleft伪元素的值为 -161px
这是一个更通用的改进版本,您可以轻松调整切片数量: https://jsfiddle.net/Labm0sop/

相关代码:
$num:25;

@for $i from 1 through $num {
span:nth-child(#{$i}) {
border-top-color: hsl($i * 15, 50%, 50%);
transform: translate(-50%,-50%) rotate($i * (360deg/$num));
}
}

#colorWheel {
width: 300px;
height: 300px;
position: relative;
border-radius: 100%;
overflow: hidden;
}

#colorWheel span {
position: absolute;
border-style: solid;
border-width: 150px (tan(360deg/(2*$num)) * 150px);
left: 50%;
top: 50%;
color:transparent;
}

输出示例:

SASS color wheel
tan()在这里实现: https://gist.github.com/kamikat/c4d472ce3c61feec6376

关于html - SASS/CSS 多色轮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60442346/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com