带边框的CSS圆环图仅添加边框到顶部

时间:2017-07-14 23:50:38

标签: css css3 css-shapes

我有这个小提琴https://jsfiddle.net/kywetbeL/19/,只有CSS和HTML。我想制作一个有5个块和边框的圆环图,每个部分之间有一个小间隙。



* {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.donut-chart {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 auto 2rem;
  border-radius: 100%
}

p.center {
  background: #ffffff;
  position: absolute;
  text-align: center;
  font-size: 28px;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  width: 130px;
  height: 130px;
  margin: auto;
  border-radius: 50%;
  line-height: 35px;
  padding: 15% 0 0;
}

.portion-block {
  border-radius: 50%;
  clip: rect(0px, 200px, 200px, 100px);
  height: 100%;
  position: absolute;
  width: 100%;
}

.circle {
  border-radius: 50%;
  clip: rect(0px, 100px, 200px, 0px);
  height: 100%;
  position: absolute;
  width: 100%;
  font-family: monospace;
  font-size: 1.5rem;
}

#part1 {
  transform: rotate(326deg);
}

#part1 .circle {
  background-color: #E64C65;
  border-top: 1px solid black;
  border-left: 1px solid black;
  border-right: 1px solid black;
  border-bottom: 1px solid black;
  animation: first 1s 1 forwards;
}

#part2 {
  transform: rotate(38deg);
}

#part2 .circle {
  background-color: #11A8AB;
  border-top: 1px solid black;
  border-left: 1px solid black;
  border-right: 1px solid black;
  border-bottom: 1px solid black;
  animation: second 1s 1 forwards 1s;
}

#part3 {
  transform: rotate(110deg);
}

#part3 .circle {
  background-color: #4FC4F6;
  border-top: 1px solid black;
  border-left: 1px solid black;
  border-right: 1px solid black;
  border-bottom: 1px solid black;
  animation: third 0.5s 1 forwards 2s;
}

#part4 {
  transform: rotate(182deg);
}

#part4 .circle {
  background-color: #4FC433;
  border-top: 1px solid black;
  border-left: 1px solid black;
  border-right: 1px solid black;
  border-bottom: 1px solid black;
  animation: fourth 0.5s 1 forwards 3s;
}

#part5 {
  transform: rotate(254deg);
}

#part5 .circle {
  background-color: #4FC888;
  border-top: 1px solid black;
  border-left: 1px solid black;
  border-right: 1px solid black;
  border-bottom: 1px solid black;
  animation: fifth 0.5s 1 forwards 4s;
}


/* Animation */

@keyframes first {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(68deg);
  }
}

@keyframes second {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(68deg);
  }
}

@keyframes third {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(68deg);
  }
}

@keyframes fourth {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(68deg);
  }
}

@keyframes fifth {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(68deg);
  }
}

<div class="container">
  <div class="donut-chart-block block">
    <div class="donut-chart">
      <div id="part1" class="portion-block">
        <div class="circle"></div>
      </div>
      <div id="part2" class="portion-block">
        <div class="circle"></div>
      </div>
      <div id="part3" class="portion-block">
        <div class="circle"></div>
      </div>
      <div id="part4" class="portion-block">
        <div class="circle"></div>
      </div>
      <div id="part5" class="portion-block">
        <div class="circle"></div>
      </div>
      <p class="center"></p>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

我似乎无法获得整个元素的边框,只有顶部。

0 个答案:

没有答案