编写一个HTML和css代码,传教一个简单的登陆表单。该表单应包含用户名和密码字段,以及一个提交按钮。设计一个css样式,使表单具有美观,且css文件需要通过外部样式在HTML代码中引入
时间: 2024-03-15 17:45:27 浏览: 58
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="login-box">
<h2>Login Form</h2>
<form>
<div class="user-box">
<input type="text" name="username" required="">
<label>Username</label>
</div>
<div class="user-box">
<input type="password" name="password" 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;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(to bottom, #333, #999);
}
.login-box {
width: 350px;
background: #fff;
padding: 40px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}
.login-box h2 {
text-align: center;
margin-bottom: 30px;
color: #333;
}
.user-box {
position: relative;
}
.user-box input {
width: 100%;
padding: 10px 0;
font-size: 16px;
color: #333;
margin-bottom: 30px;
border: none;
border-bottom: 2px solid #333;
outline: none;
background: transparent;
}
.user-box label {
position: absolute;
top: 0;
left: 0;
padding: 10px 0;
font-size: 16px;
color: #333;
pointer-events: none;
transition: 0.5s;
}
.user-box input:focus ~ label,
.user-box input:valid ~ label {
top: -20px;
left: 0;
color: #333;
font-size: 12px;
}
a {
display: inline-block;
background: #333;
color: #fff;
padding: 10px 20px;
text-decoration: none;
font-size: 18px;
border-radius: 5px;
transition: 0.5s;
margin-top: 40px;
}
a:hover {
background: #fff;
color: #333;
}
```
这段代码实现了一个简单的登录表单,包含用户名和密码字段以及一个提交按钮。CSS样式使表单看起来美观,CSS文件通过外部样式在HTML代码中引入。
阅读全文
相关推荐


















