当前位置:首页 > CSS

css制作登录界面

2026-02-12 13:18:45CSS

使用CSS制作登录界面

制作一个美观且功能完善的登录界面需要结合HTML和CSS。以下是一个完整的实现方案:

HTML结构

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录界面</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="login-container">
        <h1>用户登录</h1>
        <form class="login-form">
            <div class="input-group">
                <label for="username">用户名</label>
                <input type="text" id="username" placeholder="请输入用户名">
            </div>
            <div class="input-group">
                <label for="password">密码</label>
                <input type="password" id="password" placeholder="请输入密码">
            </div>
            <div class="remember-me">
                <input type="checkbox" id="remember">
                <label for="remember">记住我</label>
            </div>
            <button type="submit">登录</button>
            <div class="links">
                <a href="#">忘记密码?</a>
                <a href="#">注册账号</a>
            </div>
        </form>
    </div>
</body>
</html>

CSS样式

/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Arial', sans-serif;
}

body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.login-container {
    background-color: white;
    padding: 2.5rem;
    border-radius: 10px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
}

h1 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: #333;
}

.input-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: #555;
    font-weight: 500;
}

input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    transition: border-color 0.3s;
}

input[type="text"]:focus,
input[type="password"]:focus {
    border-color: #667eea;
    outline: none;
}

.remember-me {
    display: flex;
    align-items: center;
    margin-bottom: 1.5rem;
}

.remember-me input {
    margin-right: 0.5rem;
}

button {
    width: 100%;
    padding: 12px;
    background: linear-gradient(to right, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    transition: opacity 0.3s;
}

button:hover {
    opacity: 0.9;
}

.links {
    display: flex;
    justify-content: space-between;
    margin-top: 1rem;
}

.links a {
    color: #667eea;
    text-decoration: none;
    font-size: 14px;
}

.links a:hover {
    text-decoration: underline;
}

响应式设计

@media (max-width: 480px) {
    .login-container {
        padding: 1.5rem;
        margin: 0 1rem;
    }

    h1 {
        font-size: 1.5rem;
    }
}

动画效果增强

.login-container {
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

button {
    transition: transform 0.2s, opacity 0.3s;
}

button:active {
    transform: scale(0.98);
}

验证样式

input:invalid {
    border-color: #ff6b6b;
}

.error-message {
    color: #ff6b6b;
    font-size: 0.8rem;
    margin-top: 0.3rem;
    display: none;
}

input:invalid + .error-message {
    display: block;
}

暗黑模式支持

@media (prefers-color-scheme: dark) {
    .login-container {
        background-color: #2d3748;
        color: #f7fafc;
    }

    h1 {
        color: #f7fafc;
    }

    label {
        color: #e2e8f0;
    }

    input {
        background-color: #4a5568;
        color: #f7fafc;
        border-color: #4a5568;
    }
}

这个登录界面设计包含了现代UI的所有关键元素:渐变背景、卡片式布局、输入框焦点状态、按钮悬停效果、响应式设计以及可选的暗黑模式支持。可以根据实际需求调整颜色、间距和动画效果。

css制作登录界面

标签: 界面css
分享给朋友:

相关文章

制作css

制作css

CSS基础语法 CSS规则由选择器和声明块组成。选择器指向需要设置样式的HTML元素,声明块包含一个或多个用分号分隔的声明。每个声明由属性和值组成,用冒号分隔。 选择器 { 属性: 值; 属…

css 制作按钮

css 制作按钮

基础按钮样式 使用CSS创建一个基础按钮需要定义padding、background-color、border和border-radius等属性。以下是一个简单示例: .button { pad…

css制作详情页

css制作详情页

CSS制作详情页的关键步骤 布局规划 确定详情页的整体布局结构,通常包括头部、商品展示区、参数区、评价区等模块。使用Flexbox或Grid布局实现响应式设计,确保在不同设备上正常显示。 样式设计…

css如何制作三角形

css如何制作三角形

使用 border 属性制作三角形 通过设置元素的 border 属性,利用边框的透明特性可以创建三角形。将一个元素的宽度和高度设为 0,然后通过设置不同方向的边框宽度和颜色来实现。 .triang…

css简历制作

css简历制作

使用CSS制作简历的基本方法 选择简洁的布局结构,单列或双列布局适合大多数简历。使用display: flex或display: grid实现响应式设计,确保在不同设备上显示良好。 字体选择上,标题…

css制作炫酷按钮

css制作炫酷按钮

渐变背景按钮 使用CSS的linear-gradient属性创建渐变背景效果,结合阴影和过渡动画增强视觉冲击力。按钮悬停时通过改变渐变角度或颜色实现动态效果。 .gradient-btn {…