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

后端 未结 4 580
太阳男子
太阳男子 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:49

    for the pseudo version, you can also use linear-gradient (shade can be decreased or increased) and background-clip,

    where it is avalaible, mix-blend-mode can make it translucide,

    currentcolor and animation can also be used to animate color :

    .loader {
      font-size: 1.5em;
      color: gray;
      position: relative;
      padding: 3px;
      /* make a square */
      height: 100px;
      width: 100px;
      /* center content*/
      display: flex;
      align-items: center;
      justify-content: center;
      animation: coloranim infinite 5s;
    }
    
    .circle {
      border-radius: 100%;
      overflow: hidden;
    }
    
    .loader:after {
      border-radius: inherit;
      color: inherit;
      content: '';
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      padding: 3px;
      background: linear-gradient(white, white), linear-gradient(0deg, transparent 40%, currentcolor 60%), linear-gradient(50deg, transparent 50%, currentcolor 52%);
      background-clip: content-box, border-box, border-box;
      z-index: -1;
      mix-blend-mode: multiply;/* if avalaible, else bg remains white */
    }
    
    .spin:after {
      animation: spin 2s linear infinite;
    }
    
    @keyframes spin {
      to {
        transform: rotate(360deg);
      }
    }
    
    @keyframes coloranim {
      20% {
        color: tomato;
      }
      40% {
        color: purple;
      }
      60% {
        color: turquoise;
      }
      80% {
        color: green;
      }
    }
    
    
    /* demo purpose, use your own style wherever your loader is needed */
    
    html {
      height: 100%;
      display: flex;
      background: url(http://lorempixel.com/800/800/food/3);
      background-size: cover;
      box-shadow: inset 0 0 0 2000px rgba(255, 255, 255, 0.3)
    }
    
    body {
      margin: auto;
    }
    loading...

    http://codepen.io/gc-nomade/pen/YNbmGE

提交回复
热议问题