How to achieve constant rotation of div using css

藏色散人
Release: 2023-01-04 09:38:50
Original
8319 people have browsed it

Css method to realize constant rotation of div: first create a div element and give it an id value; then use inline styles to add some styles to the div; then use the "@keyframes" rule to create an animated rotate; Finally, specify animation for the div.

How to achieve constant rotation of div using css

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

Related recommendations: "css video tutorial"

css to realize div rotation all the time

1. First create a div element , and give it an id value xuanzhuan, use inline styles to add some styles to the div.

<div id="xuanzhun" style="width: 30px; height: 30px; background-color: aquamarine;">
Copy after login

How to achieve constant rotation of div using css

2. Then use the @keyframes rule to create an animation rotate

@-webkit-keyframes rotate{
    from{-webkit-transform: rotate(0deg)}
    to{-webkit-transform: rotate(360deg)}
}
@-moz-keyframes rotate{
    from{-moz-transform: rotate(0deg)}
    to{-moz-transform: rotate(359deg)}
}
@-o-keyframes rotate{
    from{-o-transform: rotate(0deg)}
    to{-o-transform: rotate(359deg)}
}
@keyframes rotate{
    from{transform: rotate(0deg)}
    to{transform: rotate(359deg)}
}
Copy after login

3. Finally, specify animation for the div.

#xuanzhun{
    -webkit-transition-property: -webkit-transform;
    -webkit-transition-duration: 1s;
    -moz-transition-property: -moz-transform;
    -moz-transition-duration: 1s;
    -webkit-animation: rotate 3s linear infinite;
    -moz-animation: rotate 3s linear infinite;
    -o-animation: rotate 3s linear infinite;
    animation: rotate 3s linear infinite;
}
Copy after login

Effect:

How to achieve constant rotation of div using css

The above is the detailed content of How to achieve constant rotation of div using css. 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