登录页面制作css
登录页面CSS设计
登录页面的CSS设计需要注重简洁、美观和用户体验。以下是一些关键的设计要点和示例代码。
基础样式设置
全局样式重置确保页面在不同浏览器中表现一致:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Arial', sans-serif;
}
设置背景和整体布局:
body {
background-color: #f5f5f5;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
登录表单容器
创建表单容器并设置样式:
.login-container {
background: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 400px;
}
表单标题样式
.login-title {
text-align: center;
margin-bottom: 1.5rem;
color: #333;
font-size: 1.8rem;
}
输入字段样式
设置输入框的通用样式:
.input-group {
margin-bottom: 1rem;
}
.input-group label {
display: block;
margin-bottom: 0.5rem;
color: #555;
}
.input-group input {
width: 100%;
padding: 0.8rem;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
}
.input-group input:focus {
outline: none;
border-color: #4a90e2;
}
按钮样式
设计提交按钮:
.login-button {
width: 100%;
padding: 0.8rem;
background-color: #4a90e2;
color: white;
border: none;
border-radius: 4px;
font-size: 1rem;
cursor: pointer;
transition: background-color 0.3s;
}
.login-button:hover {
background-color: #357abd;
}
辅助链接样式
添加忘记密码和注册链接:
.login-links {
margin-top: 1rem;
text-align: center;
}
.login-links a {
color: #4a90e2;
text-decoration: none;
font-size: 0.9rem;
}
.login-links a:hover {
text-decoration: underline;
}
响应式设计
添加媒体查询以适应不同屏幕尺寸:

@media (max-width: 480px) {
.login-container {
padding: 1.5rem;
margin: 0 1rem;
}
}
完整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 class="login-title">用户登录</h1>
<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" class="login-button">登录</button>
<div class="login-links">
<a href="#">忘记密码?</a>
<span> | </span>
<a href="#">注册新账号</a>
</div>
</form>
</div>
</body>
</html>
这些CSS样式和HTML结构共同创建了一个现代、响应式的登录页面,注重用户体验和视觉美感。可以根据具体需求调整颜色、间距和字体等细节。






