给我一个好看的前端登录界面
- User
给我一个好看的前端登录界面
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
给我一个好看的前端登录界面
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
好的,给你一个简洁、现代、并且相对容易理解和修改的前端登录界面代码示例。这个例子使用了 HTML 和 CSS 来构建结构和样式。
设计理念:
效果预览 (想象中):
一个带有柔和渐变背景的页面,中央有一个圆角、带有轻微阴影的白色(或浅色)卡片。卡片内是标题、输入框(用户名/邮箱、密码)、一个漂亮的按钮,以及“忘记密码”和“注册”的链接。
HTML 代码 (index.html):
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>好看的登录界面</title>
<link rel="stylesheet" href="style.css"> <!-- 链接到CSS文件 -->
<!-- 你也可以使用 Google Fonts 引入更漂亮的字体,例如: -->
<!-- <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet"> -->
</head>
<body>
<div class="login-container">
<form class="login-form">
<h2>用户登录</h2>
<div class="input-group">
<label for="username">用户名 或 邮箱</label>
<input type="text" id="username" name="username" required placeholder="请输入用户名或邮箱">
</div>
<div class="input-group">
<label for="password">密码</label>
<input type="password" id="password" name="password" required placeholder="请输入密码">
</div>
<button type="submit" class="login-button">登录</button>
<div class="links">
<a href="#" class="forgot-password">忘记密码?</a>
<a href="#" class="signup-link">注册新账号</a>
</div>
</form>
</div>
</body>
</html>
CSS 代码 (style.css):
/* 通用样式和重置 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
/* 可选:引入字体,如果使用了 Google Fonts */
/* font-family: 'Roboto', sans-serif; */
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%); /* 漂亮的渐变背景 */
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh; /* 使内容至少占满视口高度,实现垂直居中 */
color: #333; /* 默认文本颜色 */
line-height: 1.6;
}
.login-container {
background-color: #ffffff; /* 登录框背景 */
padding: 40px;
border-radius: 15px; /* 圆角 */
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); /* 柔和的阴影 */
width: 90%; /* 初始宽度 */
max-width: 400px; /* 最大宽度 */
text-align: center;
}
.login-form h2 {
margin-bottom: 30px;
color: #333;
font-size: 28px;
}
.input-group {
margin-bottom: 20px;
text-align: left; /* 使标签和输入框左对齐 */
}
.input-group label {
display: block; /* 标签独占一行 */
margin-bottom: 8px;
font-weight: bold;
color: #555;
font-size: 14px;
}
.input-group input {
width: 100%;
padding: 12px 15px;
border: 1px solid #ccc;
border-radius: 8px; /* 输入框圆角 */
font-size: 16px;
transition: border-color 0.3s ease; /* 边框颜色过渡效果 */
}
.input-group input:focus {
outline: none; /* 移除默认轮廓 */
border-color: #6a11cb; /* 聚焦时改变边框颜色 */
box-shadow: 0 0 5px rgba(106, 17, 203, 0.3); /* 聚焦时添加阴影 */
}
.login-button {
width: 100%;
padding: 12px;
background: linear-gradient(45deg, #6a11cb 0%, #2575fc 100%); /* 按钮渐变背景 */
color: white;
border: none;
border-radius: 8px; /* 按钮圆角 */
font-size: 18px;
font-weight: bold;
cursor: pointer;
margin-top: 20px;
transition: opacity 0.3s ease, transform 0.2s ease; /* 添加过渡效果 */
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); /* 按钮阴影 */
}
.login-button:hover {
opacity: 0.9; /* 鼠标悬停时降低透明度 */
transform: translateY(-2px); /* 鼠标悬停时轻微上移 */
}
.login-button:active {
transform: translateY(0); /* 鼠标点击时恢复位置 */
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); /* 鼠标点击时减小阴影 */
}
.links {
margin-top: 25px;
font-size: 14px;
display: flex; /* 使用 flexbox 布局链接 */
justify-content: space-between; /* 分散对齐链接 */
}
.links a {
color: #6a11cb; /* 链接颜色 */
text-decoration: none; /* 移除下划线 */
transition: color 0.3s ease;
}
.links a:hover {
color: #2575fc; /* 鼠标悬停时改变链接颜色 */
text-decoration: underline; /* 鼠标悬停时添加下划线 */
}
/* 可选:响应式调整 */
@media (max-width: 480px) {
.login-container {
padding: 30px 20px; /* 小屏幕减少内边距 */
}
.login-form h2 {
font-size: 24px;
margin-bottom: 25px;
}
.input-group input {
font-size: 15px;
padding: 10px 12px;
}
.login-button {
font-size: 16px;
padding: 10px;
}
.links {
flex-direction: column; /* 小屏幕将链接垂直排列 */
align-items: center; /* 垂直排列时居中 */
}
.links a {
margin-bottom: 10px; /* 垂直排列时添加底部间距 */
}
.links a:last-child {
margin-bottom: 0;
}
}
使用方法:
login-page。index.html 文件,并复制代码粘贴进去。style.css 文件,并复制代码粘贴进去。index.html 文件,就能看到效果了。定制建议:
body 的 linear-gradient、.login-container 的 background-color、输入框的 border-color 和 :focus 时的 border-color/box-shadow、.login-button 的 background 渐变以及 links a 的 color 来改变整体配色方案。<head> 中引入 Google Fonts 或其他字体库,然后在 CSS 的 body 或其他元素中修改 font-family。padding 和 margin 的值来改变元素之间的距离。border-radius 和 box-shadow 的值来改变卡片、输入框和按钮的圆角和阴影效果。body 的 background 改为 background-image 来使用图片背景,可能需要配合 background-size: cover; 和一个半透明的 overlay 来保证文字可读性。这个示例提供了一个良好的基础,你可以根据自己的品牌风格和喜好进行修改,打造出更具个性的登录界面。