纯css3 伪元素制作旋转小风扇

来源:互联网 发布:友盟数据 编辑:程序博客网 时间:2024/04/28 03:41

一、效果图

   

二、需求

制作旋转的小风扇,并且颜色是可以改变的

三、制作思路

只用一个标签来承载风扇,并且颜色可以任意更改,所以只能有一个标签明码定义颜色

控制旋转只要在该标签上添加动画即可

所以只用一个span标签制作中间的小圆点,使用伪元素和子元素制作周边的扇叶,背景颜色继承父元素的颜色

但是小圆点的展示出来的背景颜色应该是辅助颜色-浅灰色,外加一个黑色边框

所以我们使用边框和阴影制作出背景颜色和边框

四、代码

<span class="fan red"><i></i></span>


.fan{  display: block;  width: 0px;  height: 0px;  border-radius: 50%; border: 1px solid #999; box-shadow: 0 0 0 1px #000;position: relative; margin: 13px auto;    animation: rotateFan 5s linear infinite;-webkit-animation: rotateFan 5s linear infinite;-moz-animation: rotateFan 5s linear infinite;}@-webkit-keyframes rotateFan{ from {-webkit-transform: rotate(0deg);} to {-webkit-transform: rotate(-360deg);} }.fan i , .fan::before , .fan::after{display:  inline-block;width: 7px;height: 12px;border-radius: 24% 88%;position: absolute;background: inherit;border: 1px solid #000;}.fan i{transform: rotate(30deg);left: -6px;top: -15px;}.fan::before {content: '';transform: rotate(90deg);left: -11px;top: -2px;}.fan::after{content: '';transform: rotate(-30deg);left: 3px;top: -4px;}.red{ background: #f90005;}












原创粉丝点击