html - 我正在用 HTML 和 CSS 制作一个圆环图,需要帮助将我的跨度放在楔子的中间
问题描述
几乎我正在制作半个甜甜圈图。在互联网上找到了一些代码,但它并没有真正按照我想要的方式进行。它使用<ul>
和<li>
和边框,还使用动画来填充图表。
我试过给它一个margin-left,是的,它在de chart里面,但是把它放在中间真的很难。
.chart {
position: relative;
width: 50rem;
height: 25rem;
overflow: hidden;
}
.chart::before,
.chart::after {
position: absolute;
}
.chart::before {
content: '';
width: inherit;
height: inherit;
border: 5rem solid rgba(211, 211, 211, .3);
border-bottom: none;
border-top-left-radius: 25rem;
border-top-right-radius: 25rem;
}
.chart::after {
content: '';
left: 50%;
bottom: 10px;
transform: translateX(-50%);
font-size: 1.1rem;
font-weight: bold;
color: cadetblue;
}
.chart li {
position: absolute;
top: 100%;
left: 0;
width: inherit;
height: inherit;
border: 5rem solid;
border-top: none;
border-bottom-left-radius: 25rem;
border-bottom-right-radius: 25rem;
transform-origin: 50% 0;
transform-style: preserve-3d;
backface-visibility: hidden;
animation-fill-mode: forwards;
animation-duration: .4s;
animation-timing-function: linear;
}
.chart li:nth-child(1) {
z-index: 11;
border-color: rgb(197, 8, 8);
animation-name: rotate-one;
}
.chart li:nth-child(2) {
z-index: 10;
border-color: rgb(11, 139, 245);
animation-name: rotate-two;
animation-delay: .4s;
}
.chart li:nth-child(3) {
z-index: 9;
border-color: rgb(216, 116, 23);
animation-name: rotate-three;
animation-delay: .8s;
}
.chart li:nth-child(4) {
z-index: 8;
border-color: rgb(92, 197, 89);
animation-name: rotate-four;
animation-delay: 1.2s;
}
/* ..... here is the span or text i want centered */
.chart li span {
position: relative;
display: block;
float: left;
font-size: 1.85rem;
backface-visibility: hidden;
/**/
color: rgb(5, 5, 5);
font-weight: 600;
font-family: sans-serif;
margin-left: -2.25em;
text-align: center;
}
.chart li:nth-child(1) span {
transform: rotate(-59.65714285714286deg);
}
.chart li:nth-child(2) span {
transform: rotate(-98.22857142857143deg);
animation-delay: .4s;
}
.......... this is the animations that the wedges/borders do
@keyframes rotate-one {
100% {
transform: rotate(59.65714285714286deg);
/**
* 12% => 21.6deg
*/
}
}
@keyframes rotate-two {
0% {
transform: rotate(59.65714285714286deg);
}
100% {
transform: rotate(98.22857142857143deg);
/**
* 32% => 57.6deg
* 57.6 + 21.6 => 79.2deg
*/
}
}
<ul class="chart">
<li>
<span>116</span>
</li>
<li>
<span>75</span>
</li>
<li>
<span>47</span>
</li>
<li>
<span>44</span>
</li>
<li>
<span>38</span>
</li>
<li>
<span></span>
</li>
<li>
<span></span>
</li>
<li>
<span></span>
</li>
<li>
<span></span>
</li>
<li>
<span></span>
</li>
<li>
<span></span>
</li>
<ul>
解决方案
推荐阅读
- php-5.3 - 从 php v5.5 迁移到 php v5.3 时代码不起作用
- python - 如何在多二维列表中返回重复项?
- python - 如何在 python 中只记录我自己的消息
- python - 检查 numpy 数组是否在另一个 numpy 数组中并创建一个掩码
- javascript - 使用 Typescript/Sequelize 传递值数组
- python - 在 python 解释器中键入对象的名称 - 它调用什么方法?
- linux - 如何在 Linux 中检查对串行设备 /dev/ttySX 的正确写入
- selenium-webdriver - 有没有办法使用 Selenium Webdriver 将其转换为 Android 驱动程序???我收到“RemoteWebDriver 无法转换为 AppiumDriver”错误
- c# - 请求标头未转发到 IdentityServer4
- reactjs - 使用 TypeScript 时获取类型属性不存在错误