选项卡开发

主要是实现网页中的选项卡效果,当鼠标在标题上移动时选项卡上对应的标题也随之变化

主要代码如下:

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>选项卡页面</title>
</head>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
    height: 100%;
    width: 100%;
}

html {
    font-size: 10px;
}

.ll {
    width: 40rem;
    height: 30rem;
    border: solid 2px rgb(0, 0, 0);
    border-radius: 8px;
    overflow: hidden;
}

.qq {
    border-bottom: solid 1px rgb(0, 0, 0);
    height: 5rem;
    width: 100%;
    display: flex;
    justify-content: space-between;
    /*控制弹性容器中子元素在主轴方向上的对齐方式*/
}

.zz {
    border-right: solid 1px rgb(0, 0, 0);
    width: 33%;
    height: 5rem;
    text-align: center;
    line-height: 5rem;
    font-size: 1.8rem;
    cursor: pointer;
    /*当鼠标指针移动到应用了这个样式的元素上时,光标会变成一个“手形”图标*/
}

.qq .zz:last-child

/*控制指定子元素内容*/
    {
    border-right: none;
}

.zz:hover {
    background-color: rgb(0, 0, 0);
    color: white;
}

.gg {
    height: 100%;
    width: 100%;
    position: relative;
    /*相对定位,可用left,top,right来指导偏移量*/
    overflow: hidden;
    /*隐藏溢出内容*/
    background-color: rgb(168, 95, 95);
}

.gg .xx {
    width: 100%;
    height: 100%;
    color: rgb(0, 0, 0);
    font-size: 1.6rem;
    text-align: center;
    position: absolute;
    /*绝对定位,将元素精确的放在指定任何位置*/
    display: none;
}

.xx:nth-of-type(1)

/*控制指定子元素内容和格式效果*/
    {
    background-color: rgb(251, 0, 0);
    display: block;
}

.xx:nth-of-type(2) {
    background-color: rgb(251, 255, 0);
}

.xx:nth-of-type(3) {
    background-color: rgb(2, 28, 255);
}

</style>

<body>
<div class="ll">
<div class="qq">
<div class="zz">标题1</div>
<div class="zz">标题2</div>
<div class="zz">标题3</div>
</div>
<div class="gg">
<div class="xx">内容1</div>
<div class="xx">内容2</div>
<div class="xx">内容3</div>
</div>
</div>
<script>
let tts = document.getElementsByClassName("zz")/标题输入/
for (let i = 0; i < tts.length; i++)/大循环/ {
tts[i].onmouseenter = function () {
console.log("鼠标进入了第" + i + "个标题")
let tcs = document.getElementsByClassName("xx")
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[i].classList = "zz"
}
tts[i].classList = "zz active"
}
}
</script>
</body>

图片内容如下:

[图片上传失败...(image-e1b756-1743077781703)]

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 效果 代码展示:<!DOCTYPE html> 选项卡 * {margin: 0;padding: 0;box-...
    风流_8cce阅读 70评论 0 0
  • <!DOCTYPE html> 选择卡 * {margin: 0;padding: 0;box-sizing: ...
    木有钱阅读 59评论 0 1
  • 页面展示 代码 <!DOCTYPE html> Document /* 公共样式 */ ...
    CC言堇阅读 17评论 0 0
  • 云计算Web选项卡开发作业 1.作业效果 2.代码: <!DOCTYPE html> Documen...
    WwYiihung阅读 14评论 0 0
  • 整合之前 /** *1.大的外层的选项卡 *2.大的选项卡内部有一个小的选项卡 *3.功能 *1.自动切换 *2....
    kino2046阅读 709评论 0 50