请帮我写一个登录界面带验证码
时间: 2023-08-28 20:34:00 浏览: 49
好的,以下是一个带验证码的登录界面的HTML和CSS代码示例:
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>登录</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="login-box">
<h1>登录</h1>
<form>
<label for="username">用户名</label>
<input type="text" id="username" name="username" placeholder="请输入用户名">
<label for="password">密码</label>
<input type="password" id="password" name="password" placeholder="请输入密码">
<div class="captcha">
<input type="text" id="captcha" name="captcha" placeholder="请输入验证码">
<img src="captcha.php" alt="验证码">
</div>
<input type="submit" value="登录">
</form>
</div>
</body>
</html>
```
CSS代码:
```css
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
}
.login-box {
width: 400px;
height: 350px;
background-color: #fff;
margin: 50px auto;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}
h1 {
font-size: 24px;
text-align: center;
margin-bottom: 20px;
}
form {
display: flex;
flex-direction: column;
}
label {
font-size: 16px;
margin-bottom: 5px;
}
input[type="text"],
input[type="password"] {
padding: 10px;
margin-bottom: 20px;
border-radius: 5px;
border: none;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
.captcha {
display: flex;
flex-direction: row;
align-items: center;
margin-bottom: 20px;
}
#captcha {
flex-grow: 1;
padding: 10px;
border-radius: 5px;
border: none;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
img {
margin-left: 10px;
cursor: pointer;
}
input[type="submit"] {
background-color: #3385ff;
color: #fff;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
}
```
在示例代码中,验证码是通过一个PHP文件生成的,文件名为captcha.php。你需要在服务器上创建一个名为captcha.php的文件,并在其中编写生成验证码的代码。在示例代码中,验证码图片的src属性指向了captcha.php文件,这样访问页面时就会自动加载验证码图片。