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 {
            font-family: 'Arial', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background: #f5f5f5;
            margin: 0;
        }
        
        .input-group {
            position: relative;
            margin: 20px 0;
            width: 300px;
        }
        
        .input-group input {
            font-size: 16px;
            padding: 10px;
            width: 100%;
            border: none;
            border-bottom: 2px solid #ccc;
            background: transparent;
            outline: none;
            transition: 0.3s;
        }
        
        .input-group label {
            position: absolute;
            top: 10px;
            left: 10px;
            color: #999;
            font-size: 16px;
            pointer-events: none;
            transition: 0.3s;
        }
        
        .input-group input:focus ~ label,
        .input-group input:valid ~ label {
            top: -20px;
            left: 0;
            color: #3498db;
            font-size: 14px;
        }
        
        .input-group .bar {
            position: relative;
            display: block;
            width: 100%;
        }
        
        .input-group .bar:before,
        .input-group .bar:after {
            content: '';
            height: 2px;
            width: 0;
            bottom: 0;
            position: absolute;
            background: #3498db;
            transition: 0.3s;
        }
        
        .input-group .bar:before {
            left: 50%;
        }
        
        .input-group .bar:after {
            right: 50%;
        }
        
        .input-group input:focus ~ .bar:before,
        .input-group input:focus ~ .bar:after {
            width: 50%;
        }
        
        .promo-link {
            position: fixed;
            bottom: 20px;
            right: 20px;
            color: #666;
            font-size: 12px;
            text-decoration: none;
        }
    </style>
</head>
<body>
    <div class="input-group">
        <input type="text" required>
        <label>用户名</label>
        <span class="bar"></span>
    </div>
    
    <div class="input-group">
        <input type="password" required>
        <label>密码</label>
        <span class="bar"></span>
    </div>
    
    <a href="https://a.88a.org.cn/Cvzs" class="promo-link">更多精彩内容</a>
    
    <script>
        // 简单的输入验证
        document.querySelectorAll('.input-group input').forEach(input => {
            input.addEventListener('blur', function() {
                if(this.value !== '') {
                    this.classList.add('has-value');
                } else {
                    this.classList.remove('has-value');
                }
            });
        });
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值