skip to Main Content

I want to rotate the ball inside the circle so it touches every corner of the bigger circle and animation continuous infinitely as it is a logo animation.

body {
  background-color: #272727;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.line {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background-color: #fff;
}

.circle {
  width: 82px;
  height: 82px;
  background-color: #000;
  border-radius: 50%;
  position: absolute;
  left: 4px;
  top: 18px;
  animation: rotate 5s linear infinite;
  transform-origin: 50px 50px;
}

@keyframes rotate {
  100% {
    transform: rotate(1turn);
  }
}
<div class="line">
  <div class="circle"></div>
</div>

I implemented the code but im confused how to rotate the smaller ball through transform-origin property so that its rotate inside the bigger circle and does not come out of the bigger circle.

2

Answers


  1. You can just remove this CSS code line animation: rotate 5s linear infinite; from the .circle class and add to the .line class in your CSS code. You will achieve the animation that you want.

    body {
      background-color: #272727;
      height: 100vh;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    
    .line {
      position: relative;
      width: 100px;
      height: 100px;
      border-radius: 50%;
      background-color: #fff;
      animation: rotate 5s linear infinite;
    }
    
    .circle {
      width: 82px;
      height: 82px;
      background-color: #000;
      border-radius: 50%;
      position: absolute;
      left: 4px;
      top: 18px;
      transform-origin: 50px 50px;
    }
    
    @keyframes rotate {
      100% {
        transform: rotate(1turn);
      }
    }
    <div class="line">
      <div class="circle"></div>
    </div>

    Cheers!!!

    Login or Signup to reply.
  2. You don’t need all that code. Here is a simple version:

    .circle {
      width: 100px; /* control the size of the white circle */
      aspect-ratio: 1;
      border-radius: 50%;
      background: 
        radial-gradient(50% 50%,#000 99%,#0000 101%) no-repeat
        top/80% 80% /* adjust the 80% to control the size of the black circle*/
        #fff;
      animation: rotate 5s linear infinite;
    }
    
    @keyframes rotate {
      to {
        rotate: 1turn;
      }
    }
    
    body {
      margin: 0;
      background-color: #272727;
      height: 100vh;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    <div class="circle"></div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search