用Tab选项菜单实现登录注册界面要求只用HTML和css实现
时间: 2023-11-28 22:49:15 浏览: 34
好的,以下是一个简单的登录注册界面的HTML和CSS实现示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login/Register Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
form {
background-color: #fff;
border-radius: 5px;
padding: 20px;
width: 300px;
margin: 50px auto;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}
h2 {
text-align: center;
margin-top: 0;
}
input[type="text"], input[type="password"] {
display: block;
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: none;
border-radius: 5px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
input[type="submit"] {
background-color: #4caf50;
color: #fff;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #3e8e41;
}
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
border-radius: 5px;
}
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
border-radius: 5px 5px 0 0;
}
.tab button.active {
background-color: #ccc;
}
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
border-radius: 0 5px 5px 5px;
}
.tabcontent.active {
display: block;
}
</style>
</head>
<body>
<form>
<h2>Login/Register</h2>
<div class="tab">
<button class="tablinks active" onclick="openTab(event, 'login')">Login</button>
<button class="tablinks" onclick="openTab(event, 'register')">Register</button>
</div>
<div id="login" class="tabcontent active">
<input type="text" placeholder="Username">
<input type="password" placeholder="Password">
<input type="submit" value="Login">
</div>
<div id="register" class="tabcontent">
<input type="text" placeholder="Username">
<input type="password" placeholder="Password">
<input type="password" placeholder="Confirm Password">
<input type="submit" value="Register">
</div>
</form>
<script>
function openTab(evt, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].classList.remove("active");
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].classList.remove("active");
}
document.getElementById(tabName).classList.add("active");
evt.currentTarget.classList.add("active");
}
</script>
</body>
</html>
```
这个示例代码中,使用了`<div>`元素和CSS的样式来实现选项卡效果,JavaScript函数`openTab()`用于切换选项卡的显示。该示例中同时实现了登录和注册表单,用户可以通过切换选项卡来切换登录和注册表单的显示。