请帮我写一个html+css带验证码的登录注册界面
时间: 2024-03-18 17:43:09 浏览: 14
好的,以下是一个简单的带验证码的登录注册界面的HTML和CSS代码:
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login/Register</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
<div class="form-container sign-in-container">
<form action="#">
<h1>Sign in</h1>
<input type="email" placeholder="Email" required>
<input type="password" placeholder="Password" required>
<div class="captcha">
<img src="captcha.php" alt="CAPTCHA" />
<input type="text" name="captcha" placeholder="Enter captcha" required>
</div>
<button>Sign In</button>
</form>
</div>
<div class="form-container sign-up-container">
<form action="#">
<h1>Create Account</h1>
<input type="text" placeholder="Name" required>
<input type="email" placeholder="Email" required>
<input type="password" placeholder="Password" required>
<div class="captcha">
<img src="captcha.php" alt="CAPTCHA" />
<input type="text" name="captcha" placeholder="Enter captcha" required>
</div>
<button>Sign Up</button>
</form>
</div>
<div class="overlay-container">
<div class="overlay">
<div class="overlay-panel overlay-left">
<h1>Welcome Back!</h1>
<p>To keep connected with us please login with your personal info</p>
<button class="ghost" id="signIn">Sign In</button>
</div>
<div class="overlay-panel overlay-right">
<h1>Hello, Friend!</h1>
<p>Enter your personal details and start journey with us</p>
<button class="ghost" id="signUp">Sign Up</button>
</div>
</div>
</div>
</div>
<script src="app.js"></script>
</body>
</html>
```
CSS代码:
```css
@import url('https://fonts.googleapis.com/css?family=Montserrat:400,800');
* {
box-sizing: border-box;
}
body {
background-color: #f6f5f7;
font-family: 'Montserrat', sans-serif;
height: 100vh;
overflow: hidden;
}
.container {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 14px 28px rgba(0,0,0,0.25),
0 10px 10px rgba(0,0,0,0.22);
position: relative;
overflow: hidden;
width: 100%;
max-width: 1000px;
min-height: 550px;
}
.form-container {
position: absolute;
top: 0;
height: 100%;
transition: all 0.6s ease-in-out;
}
.sign-in-container {
left: 0;
width: 50%;
z-index: 2;
}
.sign-up-container {
left: 100%;
width: 50%;
}
.overlay-container {
position: absolute;
top: 0;
left: 50%;
width: 50%;
height: 100%;
overflow: hidden;
transition: transform 0.6s ease-in-out;
z-index: 100;
}
.overlay {
background: linear-gradient(to right, #4a90e2, #4bd1b5);
background-repeat: no-repeat;
background-size: cover;
background-position: 0 0;
color: #fff;
position: relative;
left: -100%;
height: 100%;
width: 200%;
transform: translateX(0);
transition: transform 0.6s ease-in-out;
}
.overlay-panel {
position: absolute;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 0 40px;
height: 100%;
width: 50%;
text-align: center;
transform: translateX(0);
transition: transform 0.6s ease-in-out;
}
.overlay-left {
transform: translateX(-20%);
}
.overlay-right {
right: 0;
transform: translateX(0);
}
.overlay h1 {
font-weight: bold;
margin: 0 0 30px 0;
}
.overlay p {
font-size: 1.1em;
font-weight: 500;
margin: 0 0 20px 0;
}
.overlay button {
border-radius: 20px;
border: 1px solid #fff;
background-color: transparent;
color: #fff;
font-size: 1em;
font-weight: bold;
padding: 12px 40px;
margin: 0 0 20px 0;
transition: all 0.3s ease-in-out;
}
.overlay button:hover {
background-color: #fff;
color: #4a90e2;
}
form {
background-color: #fff;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
text-align: center;
padding: 0 50px;
overflow: auto;
}
input[type=email], input[type=password], input[type=text] {
background-color: #eee;
border: none;
padding: 12px 15px;
margin: 8px 0;
width: 100%;
}
button {
border-radius: 20px;
border: none;
background-color: #4a90e2;
color: #fff;
font-size: 1.2em;
font-weight: bold;
padding: 12px 40px;
margin: 20px 0;
cursor: pointer;
transition: all 0.3s ease-in-out;
}
button:hover {
background-color: #357bd8;
}
.captcha {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin: 20px 0;
}
.captcha img {
margin-bottom: 10px;
}
@media screen and (max-width: 600px) {
.container {
min-height: 100%;
height: auto;
}
.form-container {
width: 100%;
padding: 0 20px;
}
.overlay-container {
width: 100%;
left: 0;
}
.overlay {
width: 100%;
left: 0;
}
.overlay-left, .overlay-right {
transform: translateX(0);
}
}
```
这个界面包含了两个表单,一个是登录表单,一个是注册表单,表单中都包含了一个验证码输入框。验证码的图片是通过 PHP 生成的,因此还需要一个 captcha.php 文件,代码如下:
```php
<?php
session_start();
$text = rand(10000,99999);
$_SESSION["captcha"] = $text;
$im = imagecreatetruecolor(50, 24);
$bg = imagecolorallocate($im, 22, 86, 165);
$fg = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg);
imagestring($im, 5, 5, 5, $text, $fg);
header("Cache-Control: no-cache, must-revalidate");
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
```
注意,此文件需要放在与HTML文件同一目录下。
最后,还需要一个 JavaScript 文件来控制表单的切换:
```javascript
const signUpButton = document.getElementById('signUp');
const signInButton = document.getElementById('signIn');
const container = document.getElementById('container');
signUpButton.addEventListener('click', () => {
container.classList.add("right-panel-active");
});
signInButton.addEventListener('click', () => {
container.classList.remove("right-panel-active");
});
```
将上述所有代码保存到相应的文件中,即可运行该界面。