0

Given the following source:

<head>
    <style>
        .main .item {
            animation: animate1 2s infinite;
        }

        .main .icon {
            animation: rotate1 2s infinite;
        }


        @keyframes animate1 {
            0%   { transform: scale(1) }
            100% { transform: scale(1, 1.5) }
        }
        @keyframes rotate1 {
            0%   { transform: rotate(0deg) }
            100% { transform: rotate(-5deg) }           
        }
    </style>
</head>
<body>
<div class="main">
    <div class="item">test 123</div>
    <div class="item">test 456</div>
    <div class="item icon">icon!</div>
</div>
</body>

Is there a way to get icon to have rotate1 and animate1 by a way of inheritance? I know I could list both animations on the .icon selector, but the original page has many animations with different timings.

1 Answer 1

0

Despite the fact you can apply multiple attributes on an element, separated by a comma, here you need to apply different values on the same attribute transform. Please have a look at see this answer, which explain some workaround.

Il you can't change the html structure, a subsequent approximative way would be :

<head>
  <style>
    .main {
      animation: animate1 2s infinite;
    }
    
    .main>.icon {
      animation: rotate1 2s infinite;
    }
    
    @keyframes animate1 {
      0% {
        transform: scale(1)
      }
      100% {
        transform: scale(1, 1.5)
      }
    }
    
    @keyframes rotate1 {
      0% {
        transform: rotate(0deg)
      }
      100% {
        transform: rotate(-5deg)
      }
    }
  </style>
</head>

<body>
  <div class="main">
    <div class="item">test 123</div>
    <div class="item">test 456</div>
    <div class="item icon">icon!</div>
  </div>
</body>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.