当前位置:首页 > CSS

css制作登录网页

2026-02-13 09:23:52CSS

创建HTML结构

使用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>
            <button type="submit">登录</button>
        </form>
    </div>
</body>
</html>

设计CSS样式

通过CSS美化登录页面,设置布局、颜色和交互效果。

body {
    font-family: 'Arial', sans-serif;
    background-color: #f4f4f9;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
}

.login-container {
    background: #ffffff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
}

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

.login-form {
    display: flex;
    flex-direction: column;
}

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

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: #555;
}

.input-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

.input-group input:focus {
    border-color: #007bff;
    outline: none;
}

button {
    background-color: #007bff;
    color: white;
    padding: 0.75rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #0056b3;
}

添加响应式设计

确保登录页面在不同设备上都能良好显示。

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

增强交互效果

通过CSS增加悬停和焦点状态,提升用户体验。

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

.input-group input:focus {
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

可选:添加额外功能

根据需求可以添加记住密码、忘记密码链接或社交媒体登录选项。

css制作登录网页

<div class="login-options">
    <div class="remember-me">
        <input type="checkbox" id="remember">
        <label for="remember">记住我</label>
    </div>
    <a href="#" class="forgot-password">忘记密码?</a>
</div>
.login-options {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.remember-me {
    display: flex;
    align-items: center;
}

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

.forgot-password {
    color: #007bff;
    text-decoration: none;
}

.forgot-password:hover {
    text-decoration: underline;
}

标签: 网页css
分享给朋友:

相关文章

css制作导航栏

css制作导航栏

水平导航栏 使用 display: inline-block 或 flexbox 创建水平导航栏。设置背景色、内边距和悬停效果增强交互性。 <nav class="horizontal-nav…

css字体制作

css字体制作

CSS字体设置基础 在CSS中设置字体主要通过font-family属性实现,可以指定多个字体作为备选。系统会优先使用第一个可用字体。 body { font-family: "Helvetic…

css网页制作教程下载

css网页制作教程下载

CSS网页制作教程下载资源推荐 免费在线教程平台 W3Schools(www.w3schools.com/css/)提供交互式CSS教程,涵盖基础到高级内容,支持在线练习。 MDN Web Docs(…

css怎么制作时钟

css怎么制作时钟

使用CSS制作时钟 通过CSS和少量JavaScript可以创建一个动态时钟。以下是实现方法: HTML结构 <div class="clock"> <div cla…

css制作扑克牌

css制作扑克牌

使用CSS制作扑克牌 扑克牌的样式可以通过CSS的border-radius、box-shadow和transform等属性实现。以下是一个简单的扑克牌设计示例: <div class="po…

div css制作导航

div css制作导航

导航栏的基本结构 使用HTML的<nav>标签包裹导航链接,内部通常采用无序列表<ul>和列表项<li>结构。示例代码如下: <nav> <…