纯CSS3边框按钮悬停特效

纯CSS3实现边框按钮悬停特效

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>纯CSS3边框按钮悬停特效</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: #f5f5f5;
            font-family: 'Arial', sans-serif;
        }
        
        .button-container {
            display: flex;
            flex-direction: column;
            gap: 30px;
        }
        
        /* 基础按钮样式 */
        .border-btn {
            position: relative;
            padding: 15px 30px;
            font-size: 18px;
            color: #333;
            background: transparent;
            border: none;
            cursor: pointer;
            outline: none;
            transition: all 0.3s;
            overflow: hidden;
        }
        
        /* 特效1: 四边边框动画 */
        .btn-effect-1 {
            border: 2px solid transparent;
        }
        
        .btn-effect-1:hover {
            color: #ff5252;
        }
        
        .btn-effect-1::before,
        .btn-effect-1::after {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            background: #ff5252;
            transition: all 0.3s;
        }
        
        .btn-effect-1::before {
            top: 0;
            left: 0;
        }
        
        .btn-effect-1::after {
            bottom: 0;
            right: 0;
        }
        
        .btn-effect-1:hover::before,
        .btn-effect-1:hover::after {
            width: 100%;
        }
        
        .btn-effect-1 span::before,
        .btn-effect-1 span::after {
            content: '';
            position: absolute;
            width: 2px;
            height: 0;
            background: #ff5252;
            transition: all 0.3s;
        }
        
        .btn-effect-1 span::before {
            top: 0;
            right: 0;
        }
        
        .btn-effect-1 span::after {
            bottom: 0;
            left: 0;
        }
        
        .btn-effect-1:hover span::before,
        .btn-effect-1:hover span::after {
            height: 100%;
        }
        
        /* 特效2: 对角线边框动画 */
        .btn-effect-2 {
            border: 2px solid transparent;
        }
        
        .btn-effect-2:hover {
            color: #2196F3;
        }
        
        .btn-effect-2::before,
        .btn-effect-2::after {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            background: #2196F3;
            transition: all 0.3s;
        }
        
        .btn-effect-2::before {
            top: 0;
            left: 0;
            transform-origin: left;
        }
        
        .btn-effect-2::after {
            bottom: 0;
            right: 0;
            transform-origin: right;
        }
        
        .btn-effect-2:hover::before {
            width: 100%;
            transform: rotate(45deg);
        }
        
        .btn-effect-2:hover::after {
            width: 100%;
            transform: rotate(-45deg);
        }
        
        /* 特效3: 边框填充动画 */
        .btn-effect-3 {
            border: 2px solid #4CAF50;
            color: #4CAF50;
        }
        
        .btn-effect-3:hover {
            color: white;
        }
        
        .btn-effect-3::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 0;
            background: #4CAF50;
            z-index: -1;
            transition: all 0.3s;
        }
        
        .btn-effect-3:hover::before {
            height: 100%;
        }
        
        /* 特效4: 边框光效 */
        .btn-effect-4 {
            border: 2px solid #9C27B0;
            color: #9C27B0;
            box-shadow: 0 0 10px rgba(156, 39, 176, 0);
            transition: all 0.3s;
        }
        
        .btn-effect-4:hover {
            box-shadow: 0 0 20px rgba(156, 39, 176, 0.8);
            text-shadow: 0 0 10px rgba(156, 39, 176, 0.8);
        }
        
        /* 特效5: 边框旋转动画 */
        .btn-effect-5 {
            border: 2px solid transparent;
            color: #FF9800;
        }
        
        .btn-effect-5::before,
        .btn-effect-5::after {
            content: '';
            position: absolute;
            width: 20px;
            height: 20px;
            border: 2px solid #FF9800;
            transition: all 0.5s;
        }
        
        .btn-effect-5::before {
            top: -5px;
            left: -5px;
            border-right: none;
            border-bottom: none;
        }
        
        .btn-effect-5::after {
            bottom: -5px;
            right: -5px;
            border-left: none;
            border-top: none;
        }
        
        .btn-effect-5:hover::before,
        .btn-effect-5:hover::after {
            width: calc(100% + 10px);
            height: calc(100% + 10px);
        }
        
        /* 底部链接 */
        .footer-link {
            position: fixed;
            bottom: 20px;
            color: #666;
            text-decoration: none;
            font-size: 14px;
            transition: color 0.3s;
        }
        
        .footer-link:hover {
            color: #9C27B0;
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="button-container">
        <button class="border-btn btn-effect-1">
            <span>边框动画效果1</span>
        </button>
        
        <button class="border-btn btn-effect-2">
            <span>边框动画效果2</span>
        </button>
        
        <button class="border-btn btn-effect-3">
            <span>边框动画效果3</span>
        </button>
        
        <button class="border-btn btn-effect-4">
            <span>边框动画效果4</span>
        </button>
        
        <button class="border-btn btn-effect-5">
            <span>边框动画效果5</span>
        </button>
    </div>
    

</body>
</html>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值