CSS实战:CSS实现折扇效果(可以表白哦)

前言:使用CSS做出折扇的开合效果,当鼠标悬浮上去就会开扇,移开就合扇。适合装逼,也可以用来表白哈。

开发工具:visual studio code
语言:HTML+CSS
环境:windows10
GitHub地址:扇子开合
效果图:
在这里插入图片描述
思路分析:
首先要实现十三个扇叶,考虑使用无序列表,使用13个li即可,要让这13个li能重叠显示,只需要让他们绝对定位就行。然后要让他能鼠标悬浮就旋转,考虑使用hover伪元素,同时让不同的li旋转不同的角度,最后加入过渡效果,改变旋转的圆心就行了。

完整代码:

<!--
 * @Author: CSU_XZY
 * @Date: 2020-11-13 23:49:51
 * @LastEditors: CSU_XZY
 * @LastEditTime: 2020-11-14 00:23:50
 * @FilePath: \第二天c:\Users\XZY\Desktop\前端\CSS\扇子开合\fan.html
 * @Description: just to play
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    body{
        color: bisque;
        height: 100vh;
    }
    .fan{
        width: 600px;
        height: 300px;
        position: absolute;
        top: 50%;
        left: 50%;
        margin-top: -150px;
        margin-left: -300px;
        list-style: none;
        /* border: 1px solid green; */
        
    }
    .fan li{
        position: absolute;
        width: 60px;
        height: 200px;
        background-color: aqua;
        left: 50%;
        top: 50%;
        margin-left: -30px;
        margin-top: -100px;
        text-align: center;
        font-size: 30px;
        transform-origin: center bottom;
        transition: all 1s linear;
    }
    .fan li:nth-of-type(5n)
    {
        background-color: blueviolet;
    }
    .fan li:nth-of-type(5n+1)
    {
        background-color: orange;
    }
    .fan li:nth-of-type(5n+2)
    {
        background-color: aqua;
    }
    .fan li:nth-of-type(5n+3)
    {
        background-color: red;
    }
    .fan li:nth-of-type(5n+4)
    {
        background-color: green;
    }
    .fan:hover li:nth-child(1){
        transform: rotate(15deg);
    }
    .fan:hover li:nth-child(2){
        transform: rotate(30deg);
    }
    .fan:hover li:nth-child(3){
        transform: rotate(45deg);
    }
    .fan:hover li:nth-child(4){
        transform: rotate(60deg);
    }
    .fan:hover li:nth-child(5){
        transform: rotate(75deg);
    }
    .fan:hover li:nth-child(6){
        transform: rotate(90deg);
    }
    .fan:hover li:nth-child(7){
        transform: rotate(0deg);
    }
    .fan:hover li:nth-child(8){
        transform: rotate(-15deg);
    }
    .fan:hover li:nth-child(9){
        transform: rotate(-30deg);
    }
    .fan:hover li:nth-child(10){
        transform: rotate(-45deg);
    }
    .fan:hover li:nth-child(11){
        transform: rotate(-60deg);
    }
    .fan:hover li:nth-child(12){
        transform: rotate(-75deg);
    }
    .fan:hover li:nth-child(13){
        transform: rotate(-90deg);
    }
    
</style>
<body>
    <ul class="fan">
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>        
        <li></li>        
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>       
    </ul>
</body>
</html>
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值