我要一个用html5、css3、js写成的登入页面代码
时间: 2023-04-04 18:01:11 浏览: 99
登录页面HTML+CSS+JS代码.pdf
非常感谢您的问题,以下是一个简单的使用 HTML5、CSS3 和 JavaScript 编写的登录页面代码示例:
HTML5 代码:
```
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录页面</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="login-box">
<h2>登录</h2>
<form>
<div class="user-box">
<input type="text" name="username" required="">
<label>用户名</label>
</div>
<div class="user-box">
<input type="password" name="password" required="">
<label>密码</label>
</div>
<a href="#">
<span></span>
<span></span>
<span></span>
<span></span>
提交
</a>
</form>
</div>
</body>
</html>
```
CSS3 代码:
```
* {
margin: ;
padding: ;
box-sizing: border-box;
}
body {
font-family: sans-serif;
background: #34495e;
}
.login-box {
width: 280px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #191919;
padding: 40px;
border-radius: 10px;
box-shadow: 20px rgba(, , , .2);
}
.login-box h2 {
color: #fff;
text-align: center;
margin-bottom: 30px;
}
.login-box .user-box {
position: relative;
}
.login-box .user-box input {
width: 100%;
padding: 10px ;
font-size: 16px;
color: #fff;
margin-bottom: 30px;
border: none;
border-bottom: 1px solid #fff;
outline: none;
background: transparent;
}
.login-box .user-box label {
position: absolute;
top: ;
left: ;
padding: 10px ;
font-size: 16px;
color: #fff;
pointer-events: none;
transition: .5s;
}
.login-box .user-box input:focus ~ label,
.login-box .user-box input:valid ~ label {
top: -20px;
left: ;
color: #03a9f4;
font-size: 12px;
}
.login-box a {
display: inline-block;
background: #03a9f4;
color: #fff;
padding: 10px 20px;
font-size: 16px;
border-radius: 5px;
text-decoration: none;
transition: .5s;
margin-top: 40px;
}
.login-box a:hover {
background: #fff;
color: #03a9f4;
}
```
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);
});
```
希望这个示例对您有所帮助!
阅读全文