Home  >  Article  >  Web Front-end  >  How to make an image keep rotating in css3

How to make an image keep rotating in css3

WBOY
WBOYOriginal
2022-03-28 18:34:053794browse

Method: 1. Use the "img{animation: name time infinite}" statement to bind animation to the picture; 2. Use the "@keyframes name {100%{transform:rotate(rotation angle)}}" statement Set the rotation action of animation to achieve the effect of continuous rotation of the picture.

How to make an image keep rotating in css3

The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.

How to make a picture keep rotating in css3

In css, you can use the animation attribute to bind animation to an element. The animation attribute can control the duration and number of animations. The syntax is:

animation: name duration timing-function delay iteration-count direction;

The attribute value iteration-count defines how many times the animation should be played. When set to infinite, the animation will play forever.

Then use the @keyframes rule and transform:rotate to set the rotation action of the animation.

The example is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        img{
            width:100px;
            height:100px;
            animation:fadenum 5s infinite;
        }
        @keyframes fadenum{
   100%{transform:rotate(360deg);}
}
    </style>
</head>
<body>
<img src="1118.01.png" alt="">
</body>
</html>

Output result:

How to make an image keep rotating in css3

(Learning video sharing: css video tutorial)

The above is the detailed content of How to make an image keep rotating in css3. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn