漂亮的html前端用户登录自适应UI设计模板

这是一款非常漂亮的采用自适应UI设计css+js设计的一个现代化、响应式登录html表单模板。

模板特色:

  • 简洁优雅的界面设计
  • 平滑的动画效果
  • 完整的表单验证
  • 响应式布局适配各种设备
  • 社交媒体登录选项

具体实现方法。漂亮的html前端用户登录自适应UI设计模板

HTML实现代码

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - 我的WordPress网站</title>
    <style>
        /* 基础样式重置 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }
        
        .login-container {
            background-color: white;
            border-radius: 12px;
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
            width: 100%;
            max-width: 450px;
            overflow: hidden;
            animation: fadeIn 0.5s ease-out;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .login-header {
            background: linear-gradient(to right, #4776E6, #8E54E9);
            color: white;
            padding: 30px 20px;
            text-align: center;
        }
        
        .login-header h1 {
            font-size: 28px;
            margin-bottom: 10px;
            font-weight: 600;
        }
        
        .login-header p {
            opacity: 0.9;
            font-size: 16px;
        }
        
        .login-form {
            padding: 30px;
        }
        
        .form-group {
            margin-bottom: 20px;
            position: relative;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #555;
        }
        
        .form-control {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 16px;
            transition: all 0.3s;
        }
        
        .form-control:focus {
            border-color: #4776E6;
            box-shadow: 0 0 0 2px rgba(71, 118, 230, 0.2);
            outline: none;
        }
        
        .password-toggle {
            position: absolute;
            right: 15px;
            top: 40px;
            background: none;
            border: none;
            color: #777;
            cursor: pointer;
        }
        
        .remember-forgot {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        
        .remember-me {
            display: flex;
            align-items: center;
        }
        
        .remember-me input {
            margin-right: 8px;
        }
        
        .forgot-password {
            color: #4776E6;
            text-decoration: none;
            transition: color 0.3s;
        }
        
        .forgot-password:hover {
            color: #3a63c4;
            text-decoration: underline;
        }
        
        .login-button {
            width: 100%;
            padding: 14px;
            background: linear-gradient(to right, #4776E6, #8E54E9);
            color: white;
            border: none;
            border-radius: 6px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .login-button:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(71, 118, 230, 0.4);
        }
        
        .divider {
            text-align: center;
            margin: 25px 0;
            position: relative;
            color: #777;
        }
        
        .divider::before {
            content: "";
            position: absolute;
            top: 50%;
            left: 0;
            right: 0;
            height: 1px;
            background: #eee;
        }
        
        .divider span {
            background: white;
            padding: 0 15px;
            position: relative;
            z-index: 1;
        }
        
        .social-login {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin-bottom: 20px;
        }
        
        .social-btn {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 20px;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .facebook {
            background-color: #3b5998;
        }
        
        .google {
            background-color: #dd4b39;
        }
        
        .twitter {
            background-color: #1da1f2;
        }
        
        .social-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }
        
        .register-link {
            text-align: center;
            margin-top: 20px;
            color: #555;
        }
        
        .register-link a {
            color: #4776E6;
            text-decoration: none;
            font-weight: 500;
        }
        
        .register-link a:hover {
            text-decoration: underline;
        }
        
        .error-message {
            color: #e74c3c;
            font-size: 14px;
            margin-top: 5px;
            display: none;
        }
        
        @media (max-width: 480px) {
            .login-container {
                border-radius: 0;
            }
            
            .login-form {
                padding: 20px;
            }
            
            .remember-forgot {
                flex-direction: column;
                align-items: flex-start;
                gap: 10px;
            }
        }
    </style>
</head>
<body>
    <div class="login-container">
        <div class="login-header">
            <h1>欢迎回来</h1>
            <p>登录您的账户继续访问</p>
        </div>
        
        <form class="login-form" id="loginForm">
            <div class="form-group">
                <label for="username">用户名或邮箱</label>
                <input type="text" id="username" class="form-control" placeholder="请输入用户名或邮箱">
                <div class="error-message" id="usernameError">请输入有效的用户名或邮箱</div>
            </div>
            
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" class="form-control" placeholder="请输入密码">
                <button type="button" class="password-toggle" id="togglePassword">👁️</button>
                <div class="error-message" id="passwordError">密码不能为空</div>
            </div>
            
            <div class="remember-forgot">
                <div class="remember-me">
                    <input type="checkbox" id="remember">
                    <label for="remember">记住我</label>
                </div>
                <a href="#" class="forgot-password">忘记密码?</a>
            </div>
            
            <button type="submit" class="login-button">登录</button>
            
            <div class="divider">
                <span>或使用社交账号登录</span>
            </div>
            
            <div class="social-login">
                <div class="social-btn facebook">f</div>
                <div class="social-btn google">G</div>
                <div class="social-btn twitter">t</div>
            </div>
            
            <div class="register-link">
                还没有账户? <a href="#">立即注册</a>
            </div>
        </form>
    </div>

    <script>
        // 密码显示/隐藏切换
        document.getElementById('togglePassword').addEventListener('click', function() {
            const passwordInput = document.getElementById('password');
            const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
            passwordInput.setAttribute('type', type);
            this.textContent = type === 'password' ? '👁️' : '🔒';
        });
        
        // 表单验证
        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const username = document.getElementById('username').value.trim();
            const password = document.getElementById('password').value;
            let isValid = true;
            
            // 用户名验证
            if (username === '') {
                document.getElementById('usernameError').style.display = 'block';
                isValid = false;
            } else {
                document.getElementById('usernameError').style.display = 'none';
            }
            
            // 密码验证
            if (password === '') {
                document.getElementById('passwordError').style.display = 'block';
                isValid = false;
            } else {
                document.getElementById('passwordError').style.display = 'none';
            }
            
            // 如果验证通过,可以提交表单
            if (isValid) {
                // 这里可以添加实际的登录逻辑
                alert('登录成功!在实际应用中,这里会连接到WordPress的登录系统。');
                // this.submit(); // 在实际应用中取消注释此行
            }
        });
        
        // 输入时实时验证
        document.getElementById('username').addEventListener('input', function() {
            if (this.value.trim() !== '') {
                document.getElementById('usernameError').style.display = 'none';
            }
        });
        
        document.getElementById('password').addEventListener('input', function() {
            if (this.value !== '') {
                document.getElementById('passwordError').style.display = 'none';
            }
        });
    </script>
</body>
</html>

功能特点

  1. 现代化UI设计​:采用渐变背景和卡片式布局,视觉效果出色
  2. 响应式布局​:适配从手机到桌面的各种屏幕尺寸
  3. 交互式元素​:
    • 密码显示/隐藏切换
    • 表单验证和错误提示
    • 悬停动画效果
  4. 社交媒体登录选项​:提供Facebook、Google、Twitter登录按钮
  5. 用户体验优化​:记住密码选项、忘记密码链接、注册引导

总结

这个模板不仅外观漂亮,而且功能完整,可以直接使用或根据您的品牌需求进行定制。

发表评论