html图片多tab切换代码,CSS实现Tab页切换实例代码

1.hover

移入其父元素.navI时,触发鼠标的hover态,给父元素添加样式为position:relative;z-index:1;。从而提升了层级z-index。在其子元素导航内容的层级比拼中,“子凭父贵”,父元素层级高的,其导航内容在重叠状态中显示在最上面

body,p{margin: 0;}

h2{margin: 0;font-size:100%;}

ul{margin: 0;padding: 0;list-style: none;}

a{text-decoration: none;color:inherit;}

.box{width: 572px;border: 1px solid #999;overflow: hidden;}

.nav{margin-left: -1px;font: 14px "微软雅黑";overflow: hidden;background-color: #f1f1f1;}

.navI{float: left;width: 33.333%;box-sizing: border-box;}

.navI-tit{line-height: 40px;text-align: center;cursor: pointer;border-left: 1px solid #cecece;border-bottom: 1px solid #cecece;}

.navI-txt{width: 572px;height:200px;text-indent:2em;line-height: 2;background:#fff;}

.ml1{margin-left: -100%;}

.ml2{margin-left: -200%;}

.navI_active{position:relative;z-index:1;}

/*重点代码*/

.navI:hover{position:relative;z-index:1;}

.navI:hover .navI-tit{background:#fff;border-bottom:none;}

2.锚点

点击导航标题时,触发target伪类,改变对应的导航内容的层级z-index,从而使当前导航内容在三个导航内容中胜出,在最上层显示;与此同时,改变当前导航标题的样式

body,p{margin: 0;}

h2{margin: 0;font-size:100%;}

ul{margin: 0;padding: 0;list-style: none;}

a{text-decoration: none;color:inherit;}

.box{width: 572px;border: 1px solid #999;overflow: hidden;}

.nav{margin-left: -1px;font: 14px "微软雅黑";overflow: hidden;background-color: #f1f1f1;}

.navI{float: left;width: 33.333%;box-sizing: border-box;position:relative;}

.navI-tit{position:absolute;top:0;left:0;right:0;box-sizing: border-box;line-height: 40px;height: 40px;text-align: center;cursor: pointer;border-left: 1px solid #cecece;border-bottom: 1px solid #cecece;}

.navI-txt{width: 572px;height:200px;margin-top: 40px;text-indent:2em;line-height: 2;background:#fff;}

.ml1{margin-left: -100%;}

.ml2{margin-left: -200%;}

.navI_active{z-index:1;}

/*重点代码*/

.navI-txt:target{position:relative;z-index:1;}

.navI-txt:target ~ .navI-tit{background:#fff;border-bottom:none;}

3.radio

点击导航标题时,触发checked伪类,改变对应的导航内容的层级z-index,从而使当前导航内容在三个导航内容中胜出,在最上层显示;与此同时,改变当前导航标题的样式

body,p{margin: 0;}

ul{margin: 0;padding: 0;list-style: none;}

a{text-decoration: none;color: inherit;}

input{margin: 0;padding: 0;border:none;}

.box{width:572px;border:1px solid #999;font:14px "微软雅黑";overflow:hidden;}

.nav-tit{margin-left: -1px;height: 40px;line-height: 40px;text-align: center;background-color: #f1f1f1;overflow: hidden;}

.nav-titI{box-sizing: border-box;float: left;width: 33.333%;border-left: 1px solid #cecece;border-bottom: 1px solid #cecece;cursor: pointer;}

.nav-txt{height: 200px;}

.nav-txtI{height: 200px;display:block;width: 100%;text-indent: 2em; line-height: 2;}

/*重点内容*/

.nav-txt{overflow: hidden;}

.nav-titI:hover{background-color: #fff;border-bottom:none;}

课程

学习计划

技能图谱

总结

以上所述是小编给大家介绍的CSS实现Tab页切换实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值