css登录页面代码
Certainly! Here's a simple example of an HTML login page styled with CSS:
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Page</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.login-container {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.login-container h2 {
text-align: center;
}
.login-container form {
margin-top: 20px;
}
.login-container input[type="text"],
.login-container input[type="password"] {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
.login-container input[type="submit"] {
width: 100%;
background-color: #4caf50;
color: white;
padding: 10px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
.login-container input[type="submit"]:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="login-container">
<h2>Login</h2>
<form action="#" method="post">
<input type="text" name="username" placeholder="Username" required>
<input type="password" name="password" placeholder="Password" required>
<input type="submit" value="Login">
</form>
</div>
</body>
</html>
This code creates a simple login page with a form containing fields for username and password. The CSS is used to style the page, providing a clean and modern appearance.
Sure! Here's an updated version of the login page code with additional styling and a hover effect for the login button:
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Page</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.login-container {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 300px;
}
.login-container h2 {
text-align: center;
margin-bottom: 20px;
}
.login-container form {
margin-top: 20px;
}
.login-container input[type="text"],
.login-container input[type="password"] {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
.login-container input[type="submit"] {
width: 100%;
background-color: #4caf50;
color: white;
padding: 10px 0;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.login-container input[type="submit"]:hover {
background-color: #45a049;
}
.login-container input[type="submit"]:focus {
outline: none;
}
.login-container input[type="submit"]:active {
background-color: #3e8e41;
}
</style>
</head>
<body>
<div class="login-container">
<h2>Login</h2>
<form action="#" method="post">
<input type="text" name="username" placeholder="Username" required>
<input type="password" name="password" placeholder="Password" required>
<input type="submit" value="Login">
</form>
</div>
</body>
</html>
In this version, I've made the following improvements:
Set a fixed width for the login container to ensure consistent sizing.Added margin-bottom for the <h2> element to improve spacing.Added focus and active states for the login button to enhance user interaction.Adjusted the transition timing for the button hover effect.