选项卡开放效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
}
html {
font-size: 10px;
}
.tab {
width: 30rem;
height: 40rem;
border-radius: 8px;
border: solid 2px orange;
overflow: hidden;
}
.tab-title {
width: 100%;
height: 6rem;
border-bottom: solid 2px orange;
display: flex;
justify-content: space-between;
}
.tt {
width: 33.33%;
height: 6rem;
line-height: 6rem;
font-size: 1.8rem;
text-align: center;
border-right: solid 2px orange;
}
.tab-title .tt :last-child {
border-right: none;
}
.tt active,
.tt:hover {
background-color: orange;
color: white;
}
.tab-content {
width: 100%;
height: calc(100% - 5rem);
position: relative;
background-color: aquamarine;
}
.tc {
width: 100%;
height: 100%;
text-align: center;
font-size: 2.4rem;
position: absolute;
display: none;
color: aliceblue;
}
.tc active {
display: block;
}
.tc:nth-of-type(1) {
display: red;
}
.tc:nth-of-type(2) {
background-color: blue;
}
.tc:nth-of-type(3) {
background-color: blueviolet;
}
</style>
</head>
<body>
<div class="tab">
<div class="tab-title">
<div class="tt active">标题一</div>
<div class="tt">标题二</div>
<div class="tt">标题三</div>
</div>
<div class="tab-content">
<div class="tc active">内容一</div>
<div class="tc">内容二</div>
<div class="tc">内容三</div>
</div>
</div>
<script>
let tts = document.getElementsByClassName("tt")
for (let i = 0; i < tts.length; i++) {
tts[i].onmouseenter = function () {
for (let j = 0; j < tts.length; j++) {
tts[j].classList = "tt"
}
tts[i].classList = "tt active"
let tcs = document.getElementsByClassName("tc")
for (let x = 0; x < tcs.length; x++) {
tcs[x].classList = "tc"
}
tcs[i].classList = "tc active"
}
}
</script>
</body>
</html>