代码实现
''''html
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>选项卡</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
heml,
body {
height: 100%;
width: 100%;
}
html {
font-size: 10px;
}
.tab {
width: 40rem;
height: 30rem;
border: solid 2px rgb(216, 49, 49);
border-radius: 8px;
overflow: hidden;
}
.tab-title {
border-bottom: solid 1px rgb(184, 42, 203);
height: 5rem;
width: 100%;
display: flex;
justify-content: space-between;
}
.tt {
border-right: solid 1px rgb(236, 55, 55);
width: 33%;
height: 5rem;
text-align: center;
line-height: 5rem;
font-size: 1.8rem;
cursor: pointer;
}
.tab-title .tab:last-child {
border-right: none;
}
.tt:hover {
background-color: rgb(194, 19, 217);
color: white;
}
.tab-content {
height: 100%;
width: 100%;
position: relative;
overflow: hidden;
background-color: rgb(237, 31, 31);
}
.tab-content.tc {
width: 100%;
height: 100%;
color: white;
font-size: 1.6rem;
text-align: center;
position: absolute;
display: none;
}
.tc:nth-of-type(1) {
background-color: rgb(228, 19, 19);
display: block;
}
.tc:nth-of-type(2) {
background-color: rgb(195, 0, 255);
}
.tc:nth-of-type(3) {
background-color: rgb(226, 43, 43);
}
</style>
</head>
<body>
<div class="tab">
<div class="tab-title">
<div class="tt">标题1</div>
<div class="tt">标题2</div>
<div class="tt">标题3</div>
</div>
<div class="tab-content">
<div class="tc">内容1</div>
<div class="tc">内容2</div>
<div class="tc">内容3</div>
</div>
</div>
</body>
</html>