hw04-選項(xiàng)卡開發(fā)

效果
屏幕截圖 2025-03-26 114037.png

代碼展示:<!DOCTYPE html>
<html lang="zh">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>選項(xiàng)卡</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

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

  html {
     font-size: 10px
  }

  /*公共樣式*/
  .a {
     width: 40rem;
     height: 30rem;
     border: solid 2px orange;
     /*圈定區(qū)域*/


  }

  .b {
     border-bottom: solid 1px orange;
     /*下劃線*/
     height: 5rem;
     width: 100%;
     display: flex;
     flex-direction: row;
     justify-content: space-between;
     /*左右對(duì)齊*/
  }

  .cc {

     flex: 1;
     height: 5rem;
     text-align: center;
     line-height: 5rem;
     font-size: 1.8rem;

  }

  .cc.active {
     background-color: orange;
     color: wheat;
  }

  .cc:hover {
     /*鼠標(biāo)經(jīng)過動(dòng)態(tài)先死*/
     background-color: orange;
     color: white;
  }

  .f {
     height: calc(100% - 5rem);
     width: 100%;
     position: relative;
     /*相對(duì)定位*/

     background-color: aquamarine;
  }

  .ee {
     width: 100%;
     height: 100%;
     color: white;

     text-align: center;
     position: absolute;
     /*絕對(duì)定位*/
     display: none;

  }

  .ee:nth-of-type(1) {
     background-color: burlywood;
     display: block;

  }

  .ee:nth-of-type(2) {
     background-color: aquamarine;
  }

  .ee:nth-of-type(3) {
     background-color: blueviolet;
  }

</style>

</head>

<body>
<div class="a">
<div class="b">
<div class="cc active">標(biāo)題1</div>
<div class="cc">標(biāo)題2</div>
<div class="cc">標(biāo)題3</div>
</div>
<div class="f">
<div class="ee">內(nèi)容1</div>
<div class="ee">內(nèi)容2</div>
<div class="ee">內(nèi)容3</div>
</div>
</div>
<script>
let ccs = document.getElementsByClassName("cc")
for (let i = 0; i < ccs.length; i++) {
ccs[i].onmouseenter = function () {
console.log("鼠標(biāo)進(jìn)入了第" + i + "個(gè)標(biāo)題")
let ees = document.getElementsByClassName("ee")
for (let j = 0; j < ees.length; j++) {
ees[j].style.display = "none"
}
ees[i].style.display = "block"
for (let x = 0; x < ccs.length; x++) {
ccs[x].classList = "cc"
}
ccs[i].classList = "cc active"
}
}
</script>
</body>

</html>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容