我是靠谱客的博主 深情鞋垫,这篇文章主要介绍html如何实现tab页面切换,现在分享给大家,希望可以做个参考。

本教程操作环境:windows7系统、html5版,DELL G3电脑。

html实现tab页面切换的方法:

原理:通过label标签的关联属性和input的单选类型实现相应div的显示

1、创建一个类名为wrap的div当作容器

2、创建四个label标签,这将作为tab切换项

3、在每一个label中创建一个span标签(导航内容),input标签(实现选中于取消选中)type类型为radio,还要创建一个div作为这个导航项被点中是显示内容框,

这里要注意的是input标签的name必须是相同的,我这边取名叫tab

最终HTML为下面这样:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<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的显示

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<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页面切换的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是深情鞋垫最近收集整理的关于html如何实现tab页面切换的全部内容,更多相关html如何实现tab页面切换内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(116)

评论列表共有 0 条评论

立即
投稿
返回
顶部