Home > Web Front-end > Front-end Q&A > How to create a 360-degree rotation effect on mouse hover with CSS3

How to create a 360-degree rotation effect on mouse hover with CSS3

WBOY
Release: 2022-03-30 11:48:31
Original
3100 people have browsed it

Method: 1. Use "element:hover{animation:name time;}" to bind the animation style when the mouse is hovering; 2. Use "keyframes name {100%{transform:rotate(360deg) ;}}" Just specify the 360-degree rotation action.

How to create a 360-degree rotation effect on mouse hover with CSS3

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

How to create a 360-degree rotation effect on mouse hover in CSS3

Step one: Use the :hover selector to set the style of the element when the mouse is hovering.

:Hover is a special style added when the mouse moves over the link.

Tip: The :hover selector can be used on all elements, not just links.

The animation attribute can bind an animation style to an element.

Step 2: Use keyframes rules and transform:rotate to set the 360 ​​rotation of the element.

Using @keyframes rules, you can create animations.

Create animations by gradually changing from one CSS style setting to another.

You can change the CSS style settings multiple times during the animation process.

Specify when the change occurs using %, or the keywords "from" and "to", which are the same as 0% to 100%.

The example is as follows:

<html>
<head>
    <style>
        div{
            width:100px;
            height:100px;
            background-color:pink;
            
        }
        div:hover{
        animation:fadenum 3s;
        }
        @keyframes fadenum{
   100%{transform:rotate(360deg);}
}
    </style>
</head>
<body>
    <div>360度</div>
</body>
</html>
Copy after login

Output result:

How to create a 360-degree rotation effect on mouse hover with CSS3

(Learning video sharing: css video tutorial)

The above is the detailed content of How to create a 360-degree rotation effect on mouse hover with CSS3. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template