纯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>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: #f5f5f5;
            font-family: 'Arial', sans-serif;
            flex-direction: column;
            padding: 20px;
        }

        h1 {
            margin-bottom: 50px;
            color: #333;
            text-align: center;
        }

        .button-container {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 30px;
            max-width: 800px;
            margin-bottom: 50px;
        }

        .btn {
            position: relative;
            padding: 15px 30px;
            font-size: 18px;
            text-transform: uppercase;
            letter-spacing: 2px;
            text-decoration: none;
            color: #333;
            background: transparent;
            border: none;
            cursor: pointer;
            transition: all 0.3s ease;
            overflow: hidden;
            z-index: 1;
        }

        /* 特效1: 边框从中间展开 */
        .btn-1 {
            border: 2px solid transparent;
        }

        .btn-1:hover {
            border-color: #ff4757;
        }

        .btn-1::before {
            content: '';
            position: absolute;
            top: 0;
            left: 50%;
            width: 0;
            height: 100%;
            background: #ff4757;
            transition: all 0.3s ease;
            z-index: -1;
        }

        .btn-1:hover::before {
            left: 0;
            width: 100%;
        }

        /* 特效2: 四角边框动画 */
        .btn-2 {
            border: none;
        }

        .btn-2::before,
        .btn-2::after {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            background: #2ed573;
            transition: all 0.3s ease;
        }

        .btn-2::before {
            top: 0;
            left: 0;
        }

        .btn-2::after {
            bottom: 0;
            right: 0;
        }

        .btn-2:hover::before,
        .btn-2:hover::after {
            width: 100%;
        }

        .btn-2 span::before,
        .btn-2 span::after {
            content: '';
            position: absolute;
            width: 2px;
            height: 0;
            background: #2ed573;
            transition: all 0.3s ease;
        }

        .btn-2 span::before {
            top: 0;
            right: 0;
        }

        .btn-2 span::after {
            bottom: 0;
            left: 0;
        }

        .btn-2:hover span::before,
        .btn-2:hover span::after {
            height: 100%;
        }

        /* 特效3: 边框流光效果 */
        .btn-3 {
            border: 2px solid transparent;
            position: relative;
        }

        .btn-3::before {
            content: '';
            position: absolute;
            top: -2px;
            left: -2px;
            right: -2px;
            bottom: -2px;
            z-index: -1;
            background: linear-gradient(45deg, #ff0, #f0f, #0ff, #0f0, #00f);
            background-size: 400%;
            opacity: 0;
            transition: 0.5s;
        }

        .btn-3:hover::before {
            opacity: 1;
            animation: animate 8s linear infinite;
        }

        @keyframes animate {
            0% {
                background-position: 0 0;
            }
            50% {
                background-position: 300% 0;
            }
            100% {
                background-position: 0 0;
            }
        }

        /* 特效4: 3D边框效果 */
        .btn-4 {
            border: 2px solid #3742fa;
            color: #3742fa;
            transition: all 0.3s;
        }

        .btn-4:hover {
            box-shadow: 5px 5px 0 #ff6b81, -5px -5px 0 #2ed573;
            transform: translate(2px, 2px);
        }

        /* 特效5: 边框填充效果 */
        .btn-5 {
            border: 2px solid #ffa502;
            position: relative;
            overflow: hidden;
        }

        .btn-5::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: #ffa502;
            transition: all 0.3s;
            z-index: -1;
        }

        .btn-5:hover::before {
            left: 0;
        }

        .btn-5:hover {
            color: white;
        }

        /* 特效6: 双边框效果 */
        .btn-6 {
            border: 2px solid #5352ed;
            position: relative;
        }

        .btn-6::after {
            content: '';
            position: absolute;
            top: 5px;
            left: 5px;
            right: 5px;
            bottom: 5px;
            border: 2px solid #ff6348;
            opacity: 0;
            transition: all 0.3s;
        }

        .btn-6:hover::after {
            opacity: 1;
            top: -5px;
            left: -5px;
            right: -5px;
            bottom: -5px;
        }

        .link {
            margin-top: 50px;
        }

        .link a {
            color: #5352ed;
            text-decoration: none;
            font-weight: bold;
            padding: 10px 20px;
            border: 2px solid #5352ed;
            border-radius: 30px;
            transition: all 0.3s;
        }

        .link a:hover {
            background: #5352ed;
            color: white;
        }
    </style>
</head>
<body>
    <h1>纯CSS3边框按钮悬停特效</h1>
    
    <div class="button-container">
        <button class="btn btn-1">边框展开</button>
        <button class="btn btn-2"><span>四角边框</span></button>
        <button class="btn btn-3">流光边框</button>
        <button class="btn btn-4">3D边框</button>
        <button class="btn btn-5">填充边框</button>
        <button class="btn btn-6">双边框</button>
    </div>
    
    <div class="link">
       
    </div>
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值