html,css,php编写一个好看的登陆界面
时间: 2024-01-16 12:07:56 浏览: 93
好的,我可以为您提供一些简单的示例代码,您可以根据您的需要自定义它们。首先,我们将使用HTML创建一个基本的登录表单:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="login-box">
<h2>Login</h2>
<form>
<div class="user-box">
<input type="text" name="" required="">
<label>Username</label>
</div>
<div class="user-box">
<input type="password" name="" required="">
<label>Password</label>
</div>
<a href="#">
<span></span>
<span></span>
<span></span>
<span></span>
Submit
</a>
</form>
</div>
</body>
</html>
```
接下来,我们将使用CSS来美化这个表单:
```css
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: sans-serif;
background-image: url('bg.jpg');
background-size: cover;
}
.login-box {
width: 320px;
height: 420px;
background: rgba(0, 0, 0, 0.5);
color: #fff;
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%, -50%);
box-shadow: 10px 10px 10px rgba(0, 0, 0, 0.5);
padding: 70px 30px;
}
h2 {
margin: 0;
padding: 0 0 20px;
text-align: center;
font-size: 22px;
}
.login-box label {
position: absolute;
top: 0;
left: 0;
padding: 10px 0;
font-size: 16px;
color: #fff;
pointer-events: none;
transition: 0.5s;
}
.login-box input {
width: 100%;
margin-bottom: 30px;
}
.login-box input[type="text"],
.login-box input[type="password"] {
border: none;
border-bottom: 1px solid #fff;
background: transparent;
outline: none;
height: 40px;
color: #fff;
font-size: 16px;
}
.login-box input[type="submit"] {
border: none;
outline: none;
height: 40px;
background: #fb2525;
color: #fff;
font-size: 18px;
border-radius: 20px;
}
.login-box input[type="submit"]:hover {
cursor: pointer;
background: #ffc107;
color: #000;
}
.login-box a {
text-decoration: none;
font-size: 14px;
line-height: 20px;
color: darkgrey;
display: block;
margin-top: 15px;
}
.login-box a:hover {
color: #ffc107;
}
.login-box span {
position: absolute;
display: block;
background: #fff;
height: 2px;
width: 0;
transition: 0.5s;
}
.login-box span:nth-child(1) {
top: 0;
left: 0;
width: 100%;
}
.login-box span:nth-child(2),
.login-box span:nth-child(3) {
top: 50%;
}
.login-box span:nth-child(2) {
transform: translateX(-50%);
}
.login-box span:nth-child(3) {
transform: translateX(50%);
}
.login-box span:nth-child(4) {
bottom: 0;
right: 0;
width: 100%;
}
.login-box input[type="submit"]:hover span:nth-child(1) {
width: 0;
}
.login-box input[type="submit"]:hover span:nth-child(2),
.login-box input[type="submit"]:hover span:nth-child(3) {
width: 50%;
}
.login-box input[type="submit"]:hover span:nth-child(4) {
width: 0;
}
```
最后,如果您需要使用PHP来验证登录信息,您可以将以下代码添加到您的PHP文件中:
```php
<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
// 获取表单提交的用户名和密码
$username = $_POST["username"];
$password = $_POST["password"];
// 在此处验证用户名和密码是否正确
if($username == "admin" && $password == "admin123") {
// 如果验证通过,将用户重定向到受保护的页面
header("location: protected.php");
exit();
} else {
// 如果验证失败,向用户显示错误消息
$error = "Invalid username or password.";
}
}
?>
```
希望这可以帮助您创建一个漂亮的登录界面!
阅读全文