css实现div一直旋转的方法

藏色散人
藏色散人 原创
2023-01-04 09:38:50 6159浏览

css实现div一直旋转的方法:首先创建一个div元素,并给它一个id值;然后使用内联样式给div添加一些样式;接着使用“@keyframes”规则创建一个动画rotate;最后给div指定animation即可。

本教程操作环境:windows7系统、HTML5&&CSS3版本,Dell G3电脑。

相关推荐:《css视频教程

css实现div一直旋转

1、首先创建一个div元素,并给它一个id值xuanzhuan,使用内联样式给div添加一些样式。

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

a2016409de012e750c60c87829c42ac.png

2、然后使用@keyframes规则创建一个动画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)}
}

3、最后,给div指定animation即可。

#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;
}

效果:

1.gif

以上就是css实现div一直旋转的方法的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。