1

hello i have an image with a background image and i need to do the rotation animation only for the background but the animation is applied for both of them.
this is my css code :


.to-rotate .img{
    -webkit-animation-name: rotate;
  -webkit-animation-duration:6s;
  -webkit-animation-iteration-count:infinite;
  -webkit-animation-timing-function:linear;
  -moz-animation-name: rotate;
  -moz-animation-duration:2s;
  -moz-animation-iteration-count:infinite;
  -moz-animation-timing-function:linear;
}

@-webkit-keyframes rotate {
  from {-webkit-transform:rotate(0deg);}
  to {  -webkit-transform:rotate(360deg);}
}

@-moz-keyframes rotate {
  from {-moz-transform:rotate(0deg);}
  to {  -moz-transform:rotate(360deg);}
}
Maryam Ait
  • 53
  • 1
  • 8
  • 1
    Please show relevant HTML. In this case it may be that you could use a pseudo element but there has to be something to attach it to. – A Haworth Nov 03 '21 at 18:36

1 Answers1

0

Maybe you can apply the rotation animation to another element that holds the background color/image?

.wrap {
  overflow: hidden;
}
.to-rotate {
  box-sizing: border-box;
  padding: 2rem;
  position: relative;
  width: 60vh;
  height: 60vh;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.to-rotate::before {
  content: '';
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background: url(https://i.ibb.co/PNkdKnR/bgexample.jpg) no-repeat center/cover;
      -webkit-animation-name: rotate;
  -webkit-animation-duration:6s;
  -webkit-animation-iteration-count:infinite;
  -webkit-animation-timing-function:linear;
  -moz-animation-name: rotate;
  -moz-animation-duration:2s;
  -moz-animation-iteration-count:infinite;
  -moz-animation-timing-function:linear;
  border-radius: 100%;
}

img {
  width: 100%;
  max-width: 400px;
  position: relative;
  z-index: 2;
  border: 10px solid white;
  border-radius: 100%;
}

@-webkit-keyframes rotate {
  from {-webkit-transform:rotate(0deg);}
  to {  -webkit-transform:rotate(360deg);}
}

@-moz-keyframes rotate {
  from {-moz-transform:rotate(0deg);}
  to {  -moz-transform:rotate(360deg);}
}
<div class="wrap">
  <div class="to-rotate">
    <img src="https://i.ibb.co/b6Mc5VP/egg2.jpg" alt="egg" />
  </div>
</div>
prettyInPink
  • 3,291
  • 3
  • 21
  • 32