写一个html+css+js的登录页面
时间: 2024-06-09 16:08:25 浏览: 7
以下是一个简单的 HTML+CSS+JS 登录页面的示例代码:
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;
font-family: sans-serif;
}
body {
background: #f2f2f2;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.login-box {
width: 400px;
background: #fff;
padding: 40px;
border-radius: 10px;
box-shadow: 0 0 20px 0px rgba(0, 0, 0, 0.2);
}
.login-box h2 {
text-align: center;
margin-bottom: 30px;
}
.login-box .user-box {
position: relative;
}
.login-box .user-box input {
width: 100%;
padding: 10px 0;
font-size: 16px;
margin-bottom: 30px;
border: none;
border-bottom: 1px solid #ccc;
outline: none;
background: transparent;
}
.login-box .user-box label {
position: absolute;
top: 0;
left: 0;
padding: 10px 0;
font-size: 16px;
color: #777;
pointer-events: none;
transition: 0.5s;
}
.login-box .user-box input:focus ~ label,
.login-box .user-box input:valid ~ label {
top: -20px;
left: 0;
color: #000;
font-size: 12px;
}
.login-box a {
display: inline-block;
background: #4CAF50;
color: #fff;
padding: 10px 20px;
text-decoration: none;
border-radius: 5px;
transition: 0.5s;
margin-top: 40px;
}
.login-box a:hover {
background: #fff;
color: #4CAF50;
}
.login-box a span {
position: absolute;
display: block;
height: 100%;
width: 100%;
border-radius: 5px;
transition: 0.5s;
}
.login-box a span:nth-child(1) {
top: 0;
left: -100%;
background: linear-gradient(90deg, transparent, #4CAF50);
}
.login-box a:hover span:nth-child(1) {
left: 100%;
}
.login-box a span:nth-child(2) {
top: -100%;
right: 0;
background: linear-gradient(180deg, transparent, #4CAF50);
}
.login-box a:hover span:nth-child(2) {
top: 100%;
}
.login-box a span:nth-child(3) {
bottom: 0;
right: -100%;
background: linear-gradient(270deg, transparent, #4CAF50);
}
.login-box a:hover span:nth-child(3) {
right: 100%;
}
.login-box a span:nth-child(4) {
bottom: -100%;
left: 0;
background: linear-gradient(360deg, transparent, #4CAF50);
}
.login-box a:hover span:nth-child(4) {
bottom: 100%;
}
```
JavaScript:
```javascript
const inputs = document.querySelectorAll(".user-box input");
function focusFunc() {
let parent = this.parentNode;
parent.classList.add("focus");
}
function blurFunc() {
let parent = this.parentNode;
if (this.value == "") {
parent.classList.remove("focus");
}
}
inputs.forEach(input => {
input.addEventListener("focus", focusFunc);
input.addEventListener("blur", blurFunc);
});
```
效果如下:
![](https://i.imgur.com/8nJqjvM.png)
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)