代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
}
html{
font-size: 10px;
}
.tab{
width:40rem;
height:35rem;
background-color: rgb(219, 242, 242);
}
.tab-title{
width:40rem;
height:5rem;
background-color: #e4c2c2;
display: flex;
justify-content:space-between;
flex-direction: row;
align-items: center;
border:solid 2px rgb(231, 214, 190);
}
.tt{
width:13.33rem;
height:100%;
background-color: #eff0f2;
border-right:solid 2px rgb(226, 210, 191);
text-align: center;
font-size:2rem;
}
.tt:hover{
cursor:pointer;
background-color: #4089b7;
color:white;
}
.tab-content{
width:100%;
height:calc(100% - 5rem);
background-color: aliceblue;
border:solid 2px rgb(190, 190, 237);
border-top:none;
position: relative;
}
.tc{
width:100%;
height:100%;
background-color: aquamarine;
text-align:center;
font-size:2rem;
position: absolute;
display:none;
}
.tc:nth-of-type(1){
background-color: #e47272;
display: block;
}
.tc:nth-of-type(2){
background-color: #a2d740;
}
.tc:nth-of-type(3){
background-color: #ad5c97;
}
</style>
<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>
<script>
let tts = document.getElementsByClassName("tt")
for(let i=0; i<tts.length;i++){
tts[i].onmouseenter=function(){
let tsc=document.getElement
}
}
</script>
</body>
</html>
效果呈现:
image.png