'CSS: define animations inline without a separate `keyframes` class

Generally you would define a onHover animation of a square class like this:

.square:hover {
  animation-duration: 0.5s;
  animation-name: square_hover;
}

@keyframes square_hover {
  to {background-color: yellow;}
}

Is there a way to define it like this:

.square:hover {
  animation-duration: 0.5s;
  animation: {
    to { background-color: yellow; }
  };
}

@keyframes square_hover 

?

css


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source