婷婷久久综合九色综合,欧美成色婷婷在线观看视频,偷窥视频一区,欧美日本一道道一区二区

<tt id="bu9ss"></tt>
  • <span id="bu9ss"></span>
  • <pre id="bu9ss"><tt id="bu9ss"></tt></pre>
    <label id="bu9ss"></label>

    當(dāng)前位置:首頁(yè) >  站長(zhǎng) >  編程技術(shù) >  正文

    html 實(shí)現(xiàn)tab切換的示例代碼

     2020-10-19 11:11  來(lái)源: 腳本之家   我來(lái)投稿 撤稿糾錯(cuò)

      阿里云優(yōu)惠券 先領(lǐng)券再下單

    這篇文章主要介紹了html 實(shí)現(xiàn)tab切換的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

    tab切換在項(xiàng)目中也算是常用技術(shù),一般實(shí)現(xiàn)tab切換都用js或者jq實(shí)現(xiàn),今天介紹兩種只用css實(shí)現(xiàn)tab切換方法:

    方法一:

    原理:通過(guò)label標(biāo)簽的關(guān)聯(lián)屬性和input的單選類(lèi)型實(shí)現(xiàn)相應(yīng)div的顯示

    1.創(chuàng)建一個(gè)類(lèi)名為wrap的div當(dāng)作容器

    2.創(chuàng)建四個(gè)label標(biāo)簽,這將作為tab切換項(xiàng)

    3.在每一個(gè)label中創(chuàng)建一個(gè)span標(biāo)簽(導(dǎo)航內(nèi)容),input標(biāo)簽(實(shí)現(xiàn)選中于取消選中)type類(lèi)型為radio,還要?jiǎng)?chuàng)建一個(gè)div作為這個(gè)導(dǎo)航項(xiàng)被點(diǎn)中是顯示內(nèi)容框,

    這里要注意的是input標(biāo)簽的name必須是相同的,我這邊取名叫tab

    最終HTML為下面這樣:

    <div class="wrap">
        <label>
            <span>home</span>
            <input type="radio" name="tab" checked>
            <div>home-page</div>
        </label>
        <label>
            <span>list</span>
            <input type="radio" name="tab">
            <div>list-page</div>
        </label>
        <label>
            <span>news</span>
            <input type="radio" name="tab">
            <div>news-page</div>
        </label>
        <label>
            <span>mine</span>
            <input type="radio" name="tab">
            <div>mine-page</div>
        </label>
    </div>

    重要的css,通過(guò)將input的width設(shè)為0使得input的那個(gè)小圓點(diǎn)不現(xiàn)實(shí),又通過(guò)label的關(guān)聯(lián)用導(dǎo)航項(xiàng)的點(diǎn)擊實(shí)現(xiàn)input的checked,然后通過(guò)input:checked+div{display:block}實(shí)現(xiàn)相應(yīng)div的顯示

    <style type="text/css">
            *{margin: 0;padding: 0;}
            .wrap{
                margin: 20px auto;
                width: 403px;
                height: 600px;
                border:1px solid brown;
                position: relative;
            }
            label{
                width: 100px;
                height: 30px;
                float: left;
                text-align: center;
                line-height:30px;
                border-right: 1px solid brown;
                border-bottom: 1px solid brown;
            }
            label:nth-of-type(4){
                border-right: none;
            }
            label span{
                cursor: pointer;
            }
            label div{
                width: 403px;
                height: 568px;
                position: absolute;
                left: 0;
                top: 31px;
                background: #eeeeee;
                display: none;
            }
            label input{
                width: 0;
            }
            input:checked+div{
                display: block;
            }
        </style>

    方法二:

    原理:通過(guò)a標(biāo)簽的錨點(diǎn)實(shí)現(xiàn)切換,也就a的href的路徑是要切換div的id

    1.創(chuàng)建一個(gè)類(lèi)名為wrap的div作為容器

    2.創(chuàng)建一個(gè)類(lèi)名為nav的div,在里邊創(chuàng)建四個(gè)a標(biāo)簽,a標(biāo)簽的href分別是要切換到的div的id

    3.創(chuàng)建一個(gè)和nav兄弟關(guān)系的類(lèi)名為sh的容器用來(lái)放置切換的div

    4.創(chuàng)建顯示內(nèi)容div,id分別和上面a標(biāo)簽對(duì)應(yīng)

    最終代碼如下:

    <div class="wrap">
        <div class="nav">
            <a href="#home">home</a>
            <a href="#list">list</a>
            <a href="#news">news</a>
            <a href="#mine">mine</a>
        </div>
        <div class="sh">
            <div id="home">home-page</div>
            <div id="list">list-page</div>
            <div id="news">news-page</div>
            <div id="mine">mine-page</div>
        </div>
    </div>

    css樣式設(shè)置,即將類(lèi)名為sh下的div設(shè)置為display:none;然后通過(guò)div:target{display:block}實(shí)現(xiàn)顯示選中項(xiàng)

    <style type="text/css">
            *{margin: 0;padding: 0}
            .wrap{
                width: 400px;
                height: 600px;
                border: 1px solid brown;
                margin: 20px auto;
                position: relative;
            }
            .nav{
                width: 100%;
                height: 30px;
            }
            .nav a{
                width: 99px;
                height: 30px;
                text-align: center;
                line-height: 30px;
                border-right: 1px solid brown;
                border-bottom: 1px solid brown;
                float: left;
                text-decoration: none;
                color:black;
            }
            .sh{
                width: 400px;
                height: 569px;
                position: absolute;
                left: 0;
                top:31px;
                background: #eeeeee;
            }
            .sh div{
                display: none;
                text-align: center;
            }
            .sh div:target{
                display: block;
            }
        </style>

    到此這篇關(guān)于html 實(shí)現(xiàn)tab切換的示例代碼的文章就介紹到這了,更多相關(guān)html tab切換內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!

    來(lái)源:腳本之家

    鏈接:https://www.jb51.net/web/732940.html

    申請(qǐng)創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!

    相關(guān)標(biāo)簽
    html

    相關(guān)文章

    熱門(mén)排行

    信息推薦