tab切换在项目中也算是常用技术,一般实现tab切换都用js或者jq实现,今天介绍两种只用css实现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>
方法二:
原理:通过a标签的锚点实现切换,也就a的href的路径是要切换div的id
1.创建一个类名为wrap的div作为容器
2.创建一个类名为nav的div,在里边创建四个a标签,a标签的href分别是要切换到的div的id
3.创建一个和nav兄弟关系的类名为sh的容器用来放置切换的div
4.创建显示内容div,id分别和上面a标签对应
最终代码如下:
<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下的div设置为display:none;然后通过div:target{display:block}实现显示选中项
<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>
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新动态
- 《饿殍:明末千里行》行将就木的日月山河
- 【古典音乐】卡拉扬《马勒·大地之歌》2013[FLAC+CUE/整轨]
- KOKIA《EVOLVEtoLOVE20周年精逊4CD【FLAC】
- 李娜(昌圣法师)-《唱经给你听.念佛礼仪》[APE]
- 前《龙腾世纪》编剧谈EA用AI做游戏:他们的兴奋是绝望的哀嚎
- 世界公认最丑的鱼登热搜 科普:其实是人为被迫毁容
- 网易新作合约要求测试者不准说坏话:现已撤回并道歉
- 【原神】V4.6攻略 | 全角色突破用讨伐材料汇总
- 【原神】V4.6攻略 | 4.6版本下半抽卡建议
- 【原神】V4.6攻略 | 那维莱特的一条龙机制介绍、养成及配队
- 郑智化.1995-游戏人间【飞碟】【WAV+CUE】
- 群星.1999-唱好香港【STAREAST】【WAV+CUE】
- 美宝.2013-从目的地出发【金牌大风】【WAV+CUE】
- 新生 New Life
- 站长 Chief of Station