输入框标签提示效果

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>输入框标签提示效果</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Arial', sans-serif;
        }
        
        body {
            background-color: #f5f7fa;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            padding: 20px;
        }
        
        .form-container {
            background: white;
            padding: 40px;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 500px;
        }
        
        h1 {
            text-align: center;
            margin-bottom: 30px;
            color: #2c3e50;
        }
        
        .form-group {
            position: relative;
            margin-bottom: 30px;
        }
        
        .form-input {
            width: 100%;
            padding: 15px;
            font-size: 16px;
            border: 2px solid #e0e0e0;
            border-radius: 5px;
            transition: all 0.3s ease;
            background-color: transparent;
            z-index: 1;
            position: relative;
        }
        
        .form-input:focus {
            border-color: #3498db;
            outline: none;
            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
        }
        
        .form-label {
            position: absolute;
            left: 15px;
            top: 15px;
            color: #95a5a6;
            font-size: 16px;
            transition: all 0.3s ease;
            background-color: white;
            padding: 0 5px;
            z-index: 0;
        }
        
        /* 当input获得焦点或有内容时,label上移并缩小 */
        .form-input:focus + .form-label,
        .form-input:not(:placeholder-shown) + .form-label {
            top: -10px;
            left: 10px;
            font-size: 12px;
            color: #3498db;
            z-index: 2;
            background-color: white;
        }
        
        .submit-btn {
            width: 100%;
            padding: 15px;
            background: linear-gradient(to right, #3498db, #2c3e50);
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        }
        
        .submit-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
        }
        
        .website-link {
            display: block;
            text-align: center;
            margin-top: 30px;
            color: #3498db;
            font-weight: bold;
            text-decoration: none;
            transition: color 0.3s;
        }
        
        .website-link:hover {
            color: #2c3e50;
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="form-container">
        <h1>用户登录</h1>
        
        <form>
            <div class="form-group">
                <input type="text" class="form-input" id="username" placeholder=" " required>
                <label for="username" class="form-label">用户名</label>
            </div>
            
            <div class="form-group">
                <input type="password" class="form-input" id="password" placeholder=" " required>
                <label for="password" class="form-label">密码</label>
            </div>
            
            <button type="submit" class="submit-btn">登录</button>
            

        </form>
    </div>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值