用html写一个漂亮的登录页面含注册功能,表单居中
时间: 2024-05-10 21:15:33 浏览: 11
以下是一个简单的 HTML 登录页面示例,包含注册功能和表单居中:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<style type="text/css">
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
}
.container {
margin: 0 auto;
width: 400px;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}
h1 {
text-align: center;
margin-bottom: 30px;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 10px;
border-radius: 5px;
border: none;
margin-bottom: 20px;
}
input[type="submit"] {
background-color: #4CAF50;
color: #fff;
padding: 10px;
border-radius: 5px;
border: none;
cursor: pointer;
width: 100%;
margin-bottom: 20px;
}
.register {
text-align: center;
font-size: 14px;
}
.register a {
color: #4CAF50;
text-decoration: none;
}
</style>
</head>
<body>
<div class="container">
<h1>Login</h1>
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<input type="submit" value="Login">
<div class="register">Don't have an account? <a href="#">Register here</a></div>
</form>
</div>
</body>
</html>
```
在这个示例中,使用了 CSS 居中表单。`.container` 类设置了 `margin: 0 auto`,它将水平居中容器,因为它有一个固定的宽度 `width: 400px`。如果你想使用不同的宽度,可以更改 `.container` 类的 `width` 属性。