CSS3 学习笔记——鼠标滑过按钮特效(一)

鼠标滑过按钮特效(一)

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>按钮特效</title>
<style>
    #container{
        width:450px;
        margin:50px auto;
    }
    .btn{
        outline: none;
        cursor:pointer;
        position: relative;
        width:100px;
        height:40px;
        border-radius:5px;
        text-align:center;
        line-height: 40px;
        font-size:18px;
        color:#fff;
        overflow: hidden;
    }
    .btn.btn-primary{
         background-color:#337ab7;
         border:1px solid #337ab7;
    }
    .btn.btn-secondary{
        border:1px solid #5bc0de;
        background-color:#5bc0de;
    }
    .btn.btn-warning{
        border:1px solid #f0ad4e;
        background-color:#f0ad4e;
    }
    .btn.btn-success{
        border:1px solid #5cb85c;
        background-color:#5cb85c;
    }
    .btn .mask{
        position:absolute;
        opacity: 1;
        background-color:#fff;
     }

    .btn .mask.to-left{
        height:100%;
        width:0;
        right:0px;
     }    
    .btn .mask.to-right{
        height:100%;
        width:0px;
        left:0px;
        border-top-right-radius: 40px;
     }    
    .btn .mask.to-spread{
        height:0%;
        width:0px;
        left:50%;
        top:50%;
        transform:translate(-50%,-50%);
        border-radius: 5px;
     }    
    .btn .mask.to-top{
        width:100%;
        height:0px;
        bottom:0px;
        left:0px;
     }
    .btn.btn-primary:hover span.mask{
        animation:btn-to-left 1s;
    } 
    .btn.btn-secondary:hover span.mask{
        animation:btn-to-right 1s;
    } 
    .btn.btn-warning:hover span.mask{
        animation:btn-to-spread 1s 1;
    } 
    .btn.btn-success:hover span.mask{
        animation:btn-to-top 1s 1;
    } 
    @keyframes btn-to-left{
        from{
            width:0px;
            opacity:1;
        }
        to{
            width:100%;
            opacity:0;
        }
    } 
    @keyframes btn-to-right{
        from{
            width:0px;
            opacity:1;
        }
        to{
            width:100%;
            opacity:0;
        }
    }     
    @keyframes btn-to-spread{
        from{
            width:0%;
            height:0%;
            opacity:1;
        }
        to{
            width:100%;
            height:200%;
            opacity:0;
        }
    }     
    @keyframes btn-to-top{
        from{
            height:0%;
            opacity:1;
        }
        to{
            height:100%;
            opacity:0;
        }
    }  
</style>
</head>
<body>
    <div id='container'>
        <button class='btn btn-primary'>按钮一
            <span class="mask to-left"></span>
        </button>
        <button class='btn btn-secondary'>按钮二
            <span class="mask to-right"></span>
        </button>
        <button class='btn btn-warning'>按钮三
            <span class="mask to-spread"></span>
        </button>
        <button class='btn btn-success'>按钮四
            <span class="mask to-top"></span>
        </button>
    </div>
</body>
</html>

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值