用html和css做一个登录界面
时间: 2023-12-22 13:05:45 浏览: 26
好的,下面是一个简单的登录界面示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
<style>
body {
background-color: #f2f2f2;
}
.container {
width: 400px;
margin: 0 auto;
margin-top: 100px;
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.2);
}
h1 {
text-align: center;
color: #333;
}
input[type=text], input[type=password] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
button {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
width: 100%;
}
button:hover {
background-color: #45a049;
}
</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>
<button type="submit">Login</button>
</form>
</div>
</body>
</html>
```
使用CSS样式可以使登录界面更美观和易于使用。在这个示例中,我们使用了一个`container`类来包装登录表单,使用`box-shadow`属性来添加一个阴影效果,使用`border-radius`属性来使边框圆角化。同时,我们使用了`input`标签和`label`标签来创建用户名和密码输入框,并使用`button`标签来创建登录按钮。最后,使用`hover`伪类来添加当鼠标悬停在登录按钮上时的效果。