小編給大家分享一下html實現tab頁面切換的方法,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
html實現tab頁面切換的方法:首先創建一個類名為wrap的div當作容器;然后創建四個label標簽,在每一個label中創建一個span標簽;最后創建一個div作為這個導航項。
html實現tab頁面切換的方法:
原理:通過label標簽的關聯屬性和input的單選類型實現相應div的顯示
1、創建一個類名為wrap的div當作容器
2、創建四個label標簽,這將作為tab切換項
3、在每一個label中創建一個span標簽(導航內容),input標簽(實現選中于取消選中)type類型為radio,還要創建一個div作為這個導航項被點中是顯示內容框,
這里要注意的是input標簽的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,通過將input的width設為0使得input的那個小圓點不現實,又通過label的關聯用導航項的點擊實現input的checked,然后通過input:checked+div{display:block}實現相應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>看完了這篇文章,相信你對“html實現tab頁面切換的方法”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。