登录页面制作css
登录页面基础结构
使用HTML构建登录表单的基本框架,包含用户名、密码输入框和提交按钮。
<div class="login-container">
<h1>用户登录</h1>
<form>
<div class="form-group">
<label for="username">用户名</label>
<input type="text" id="username" placeholder="输入用户名">
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" id="password" placeholder="输入密码">
</div>
<button type="submit">登录</button>
</form>
</div>
容器样式设计
设置登录容器的基本样式,包括宽度、背景和阴影效果。
.login-container {
width: 300px;
margin: 100px auto;
padding: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.login-container h1 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
表单元素样式
为表单中的输入框和标签添加样式,增强视觉效果和用户体验。
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
color: #666;
}
.form-group input {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
.form-group input:focus {
border-color: #4CAF50;
outline: none;
}
按钮样式设计
为登录按钮添加样式,包括悬停和活动状态效果。

button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #45a049;
}
button:active {
background-color: #3e8e41;
}
响应式设计
添加媒体查询确保登录页面在不同设备上都能正常显示。
@media (max-width: 400px) {
.login-container {
width: 90%;
margin: 50px auto;
}
}
动画效果
为登录表单添加简单的过渡动画,提升用户体验。

.login-container {
transition: all 0.3s ease;
}
button {
transition: background-color 0.3s ease;
}
.form-group input {
transition: border-color 0.3s ease;
}
错误状态样式
为表单验证错误的情况添加特殊样式。
.error {
color: #f44336;
font-size: 12px;
margin-top: 5px;
}
.form-group.error input {
border-color: #f44336;
}
记住我选项
添加记住我复选框和相关样式。
<div class="remember-me">
<input type="checkbox" id="remember">
<label for="remember">记住我</label>
</div>
.remember-me {
display: flex;
align-items: center;
margin-bottom: 15px;
}
.remember-me input {
width: auto;
margin-right: 10px;
}
忘记密码链接
添加忘记密码链接并设置样式。
<div class="forgot-password">
<a href="#">忘记密码?</a>
</div>
.forgot-password {
text-align: right;
margin-top: -10px;
margin-bottom: 15px;
}
.forgot-password a {
color: #666;
text-decoration: none;
font-size: 12px;
}
.forgot-password a:hover {
color: #4CAF50;
}






