<!DOCTYPE html>
<html lang="zh">
<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 {
height: 50rem;
width: 60rem;
background-color: antiquewhite;
border-radius: 8px;
border: solid 2px #ebd0d0;
overflow: hidden;
}
.tab-title {
width: 100%;
height: 5rem;
background-color: rgb(207, 229, 247);
border-bottom: solid 2px #e9cccc;
display: flex;
justify-content: space-between;
}
.tt {
width: 33%;
height: 100%;
font-size: 1.5rem;
border-right: solid 2px #e9cccc;
text-align: center;
line-height: 5rem;
cursor: pointer;
}
.tt:nth-of-type(1) {
background-color: beige;
}
.tt:nth-of-type(3) {
border-right: none;
}
.tt:hover {
background-color: aliceblue;
color: #ebd0d0;
}
.tab-content {
width: 100%;
height: 100%;
background-color: beige;
position: relative;
}
.tc {
width: 100%;
height: 100%;
position: absolute;
display: none;
text-align: center;
}
.tc:nth-of-type(1) {
background-color: #ebd0d0;
display: block;
text-align: center;
font-size: 1.8rem;
}
.tc:nth-of-type(2) {
background-color: azure;
}
.tc:nth-of-type(3) {
background-color: beige;
}
</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>
<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>

选项卡开发
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 鸿蒙应用开发从入门到入行 第八天 - Tabs选项卡 导读:在本篇文章里,您将掌握使用Tabs选项卡做栏目分类,这...