2025-03-22

作業(yè)分析

本次要求在編寫(xiě)一個(gè)簡(jiǎn)易的選項(xiàng)卡效果效果如下圖


image.png

image.png

image.png

代碼實(shí)現(xiàn)

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

<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 1px #000;
        }

        .tab-title {
            width: 100%;
            height: 5rem;
            background-color: antiquewhite;
            border-bottom: solid 2px orange;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .tt {
            flex: 1;
            height: 5rem;
            background-color: #fff;
            font-size: 1.8rem;
            text-align: center;
            line-height: 5rem;
        }

        .tt.active,
        .tt:hover {
            background-color: orange;
            color: white;
        }

        .tab-content {
            width: 100%;
            height: calc(100% - 5rem);
            background-color: aquamarine;
            position: relative;
        }

        .tc {
            width: 100%;
            height: 100%;
            font-size: 1.8rem;
            text-align: center;
            color: white;
            position: absolute;
            display: none;
        }

        .tc.active {
            display: block;
        }

        .tc:nth-of-type(1) {
            background-color: blue;
        }

        .tc:nth-of-type(2) {
            background-color: green;
        }

        .tc:nth-of-type(3) {
            background-color: red;
        }
    </style>
</head>

<body>
    <div class="tab">
        <div class="tab-title">
            <div class="tt active">標(biāo)題1</div>
            <div class="tt">標(biāo)題2</div>
            <div class="tt">標(biāo)題3</div>
        </div>
        <div class="tab-content">
            <div class="tc active">內(nèi)容部分1</div>
            <div class="tc">內(nèi)容部分2</div>
            <div class="tc">內(nèi)容部分3</div>
        </div>
    </div>
    <script>
        let tts = document.getElementsByClassName("tt")
        for (let i = 0; i < tts.length; i++) {
            tts[i].onmouseenter = function () {
                for (let j = 0; j < tts.length; j++) {
                    tts[j].classList = "tt"
                }
                tts[i].classList = "tt active"
                let tcs = document.getElementsByClassName("tc")
                for (let x = 0; x < tcs.length; x++) {
                    tcs[x].classList = "tc"
                }
                tcs[i].classList = "tc active"
            }
        }
    </script>
</body>

</html>

個(gè)人總結(jié)

利用好循環(huán)結(jié)構(gòu)可以簡(jiǎn)化很多步驟,勤加練習(xí)熟悉循環(huán)結(jié)構(gòu),編寫(xiě)更多作品

?著作權(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)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

  • 避免腦卒中四大要素 腦卒中,又稱中風(fēng),是一種嚴(yán)重威脅人類健康的疾病。了解并掌握避免腦卒中的關(guān)鍵要素,對(duì)我們的健康至...
    期頤堂閱讀 39評(píng)論 0 0
  • 頁(yè)面展示 代碼 <!DOCTYPE html> Document /* 公共樣式 */ ...
    CC言堇閱讀 41評(píng)論 0 0
  • 腰間盤(pán)退行性變是指腰椎間盤(pán)隨年齡增長(zhǎng)自然老化,導(dǎo)致結(jié)構(gòu)功能逐漸退化的生理病理過(guò)程。這一過(guò)程涉及椎間盤(pán)纖維環(huán)、髓核、...
    紙殼子123閱讀 102評(píng)論 0 0
  • 筑基課清盤(pán)收獲:基礎(chǔ)心理學(xué)需要和動(dòng)機(jī)、人格和氣質(zhì) 第一單元需要的概述, 需要:有機(jī)體內(nèi)部的一種不平衡狀態(tài)。特點(diǎn)包括...
    呼建榮閱讀 64評(píng)論 0 0
  • 奇亞籽富含 Omega-3 脂肪酸(含量達(dá) 53%),每湯匙提供 4.9 克亞麻酸,是三文魚(yú)的 3 倍。這種必需脂...
    小滿1閱讀 115評(píng)論 0 0

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