Is it possible to draw a partial circle outline in CSS (open ring shape)?

后端 未结 4 554
太阳男子
太阳男子 2020-12-08 20:00

I\'m interested in creating a loading spinner entirely in CSS but in order to do so I would need to be able to draw a open ring shape like this:

The ring wo

4条回答
  •  执笔经年
    2020-12-08 20:46

    To create a circle that gradually draws it's outer path, use SVG.

    SVG's stroke-dasharray property will turn any path into a dashed line, which you can use to your advantage by setting the dash size to be almost as long as the path itself.

    Then use a CSS animation to gradually change the stroke-dashoffset to move the dash around the perimeter of your circle.

    circle {
      fill: white;
      stroke: black;
      stroke-width: 2;
      stroke-dasharray: 250;
      stroke-dashoffset: 1000;
      animation: rotate 5s linear infinite;
    }
    
    @keyframes rotate {
      to {
        stroke-dashoffset: 0;
      }
    }
    
      
    

提交回复
热议问题