用HTML和css写一个前端登陆界面
时间: 2024-05-30 07:15:51 浏览: 15
<!DOCTYPE html>
<html>
<head>
<title>前端登陆界面</title>
<style>
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
}
h1 {
text-align: center;
color: #333;
margin-top: 50px;
}
form {
max-width: 400px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
margin-top: 30px;
}
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;
}
.container {
text-align: center;
margin-top: 20px;
}
.error-message {
color: red;
font-size: 12px;
margin-top: 8px;
}
</style>
</head>
<body>
<h1>前端登陆界面</h1>
<form>
<label for="username"><b>用户名</b></label>
<input type="text" placeholder="请输入用户名" name="username" id="username" required>
<label for="password"><b>密码</b></label>
<input type="password" placeholder="请输入密码" name="password" id="password" required>
<button type="submit">登陆</button>
<div class="container">
<span class="psw"><a href="#">忘记密码?</a></span>
</div>
<div class="error-message" id="error-message"></div>
</form>
<script>
// 表单提交事件
document.querySelector('form').addEventListener('submit', function(event) {
event.preventDefault(); // 阻止表单默认提交行为
// 获取用户名和密码
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
// 判断用户名和密码是否为空
if (username.trim() === '' || password.trim() === '') {
document.getElementById('error-message').innerText = '用户名和密码不能为空';
return;
}
// 跳转到登录成功页面
window.location.href = 'success.html';
});
</script>
</body>
</html>
相关推荐
![](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)
![](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)