Search code examples
htmlcssborderspinner

CSS Rotate only the border


I want to make three circle spinners spinning around the text and the text inside these spinners will stay still.

I am only allowed to do this with CSS by referring to the .spinner-border in Bootstrap. The HTML file cannot be modified.

.loader-wrapper {
  position: fixed;
  width: 100%;
  height: 100%;
  text-align: center;
  z-index: 1;
}

@-webkit-keyframes spinner-border {
  to {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

@keyframes spinner-border {
  to {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

.loader {
  position: relative;
  left: auto;
  top: auto;
  width: 80px;
  font-size: 20px;
  text-align: center;
  display: inline-block;
  width: 10rem;
  height: 10rem;
  vertical-align: text-center;
  border: 0.25em solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  -webkit-animation: spinner-border .75s linear infinite;
  animation: spinner-border .75s linear infinite;
}
<div class="loader-wrapper">
  <div class="loader">Loading</div>
</div>

I have tried to make one spinner first. But I don't know how to make the text stay still.


Solution

  • .loader-wrapper {
      position: fixed;
      width: 100%;
      height: 100%;
      text-align: center;
      z-index: 1;
    }
    
    @-webkit-keyframes spinner-border {
      to {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
      }
    }
    
    @keyframes spinner-border {
      to {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
      }
    }
    
    .loader {
      position: relative;
      top: 5px;
      left: auto;
      width: 80px;
      font-size: 20px;
      text-align: center;
      display: inline-block;
      width: 10rem;
      height: 10rem;
      vertical-align: text-center;
      
    }
    .loader::after {
      content: '';
      position: absolute;
      left: 0;
      top: -10px;
      width: 100%;
      height: 100%;
      border: 0.25em solid currentColor;
      border-right-color: transparent;
      border-radius: 50%;
      -webkit-animation: spinner-border .75s linear infinite;
      animation: spinner-border .75s linear infinite;
    }
    <div class="loader-wrapper">
      <div class="loader">Loading</div>
    </div>