css animation
时间: 2023-10-12 13:20:33 浏览: 86
CSS animation allows you to animate HTML elements using CSS. You can define animations for various elements, including text, images, and buttons. Animations can be triggered by different events, such as hovering over an element, clicking on it, or scrolling.
To create a CSS animation, you first need to define the animation using the `@keyframes` rule, which specifies the animation's name, duration, and the keyframes that define the animation's progress. Then, you can apply the animation to an element using the `animation` property, which specifies the animation's name, duration, timing function, and other properties.
Here's an example of a simple CSS animation that rotates an image:
```
@keyframes rotate {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
img {
animation: rotate 2s linear infinite;
}
```
This animation defines the `rotate` animation, which rotates an element from 0 degrees to 360 degrees. The `img` element is then animated using the `rotate` animation, which lasts for 2 seconds, has a linear timing function, and repeats infinitely.
阅读全文