效果如下

{502B5B31-82FC-4119-BB7C-071165335AD1}.png
代码如下
<!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;}
html,body{
height: 100%;
width: 100%;
}
html{
font-size: 10px;
}
.tab{
width: 40rem;
height: 30rem;
border:solid 2px orange;
border-radius:8px;
overflow:hidden;
}
.title{
border-bottom:solid 1px orange;
height:50px;
width:100%;
display:flex;
justify-content: space-between;
}
.tt{
border-right: solid 1px orange;
width:33%;
height:5rem;
text-align:center;
line-height: 5rem;
font-size:1.8rem;
cursor: pointer;
}
.title .tt:last-child {
border-right:none;
}
.tt:hover{
background-color: orange;
color:white;
}
.content{
height:100%;
width: 100%;
position: relative;
overflow:hidden;
background-color:aquamarine;
}
.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:burlywood;
display: block;
}
.tc:nth-of-type(2){
background-color:aquamarine;
}
.tc:nth-of-type(3){
background-color:blueviolet;
}
</style>
</head>
<body>
<div class="tab">
<div class="title">
<div class="tt">标题1</div>
<div class="tt">标题2</div>
<div class="tt">标题3</div>
</div>
<div class="content">
<div class="tc">内容1</div>
<div class="tc">内容2</div>
<div class="tc">内容3</div>
</div>
</div>
<script>
let tts=document.getElementsByClassName("tt")
for(let i=0;i<tts.length;i++){
tts[i].onmouseenter = function() {
console.log("鼠标进入了第" + i + "个标题")
let tcs = document.getElementsByClassName("tc")
for(let j = 0; j < tcs.length; j++) {
tcs[j].style.display = "none"
}
tcs[i].style.display = "block"
for(let x = 0; x < tts.length; x++) {
tts[x].classList = "tt"
}
tts[i].classList = "tt active"
}
}
</script>
</body>
</html>