r/code • • Jun 11 '26

Help Please why won't my animation work ???

OKAY UHH FOUND OUT WHAT WAS WRONG;;; just needed to add a letter in the class name lmao....anyways thank you 👅

hi...so i've been reworking my media page and i wanted to add some spinning flower images that stop when you hover them. the animation worked until i added the 1 and 2 classes so they'd spin in different ways...idk what went wrong lmao???

you can check out my source code here

here's the css:

     .flower{
        position: absolute;
        transition: filter 1s linear;
      }
      
      .flower:hover{
        animation-play-state: paused;
        filter: brightness(117%) hue-rotate(18deg) saturate(153%) contrast(120%);
        -webkit-filter: brightness(117%) hue-rotate(18deg) saturate(153%) contrast(120%);
        -moz-filter: brightness(117%) hue-rotate(18deg) saturate(153%) contrast(120%);
      }
      
      .1{
        animation: spinR 3s linear infinite;
      }
      
      .2{
        animation: spinL 3s linear infinite;
      }

  @keyframes spinL {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
      }
      
      @keyframes spinR {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(-360deg); }
      }

and here's the html

<img src="images/media/flower1.png" class="flower 1" style="top: -50px; left: -100px;">
    <img src="images/media/flower2.png" class="flower 2" style="top: 780px; right: -30px;">

what am i missing here ??? am i just stupid ??? 😭

5 Upvotes

2 comments sorted by

2

u/Toastti Jun 11 '26

Change the class names for the flower. The .1 and .2 selectors seem to be the issue

<img src="images/media/flower1.png" class="flower spinR" style="top: -50px; left: -100px;">
<img src="images/media/flower2.png" class="flower spinL" style="top: 780px; right: -30px;">
.flower {
  position: absolute;
  transition: filter 1s linear;
}

.flower:hover {
  animation-play-state: paused;
  filter: brightness(117%) hue-rotate(18deg) saturate(153%) contrast(120%);
}

.spinR {
  animation: spinR 3s linear infinite;
}

.spinL {
  animation: spinL 3s linear infinite;
}

@keyframes spinL {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

@keyframes spinR {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(-360deg);
  }
}

2

u/AshleyJSheridan Jun 12 '26

Yeah, class names need to start with a letter I believe. This limitation is part of the CSS selectors, rather than a limitation on what the HTML can use.