这篇文章主要介绍了CSS实现Tab页切换的案例,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。1.hover移入其父元素.navI时,触发鼠标的hover态,给父元素添加样式为
这篇文章主要介绍了CSS实现Tab页切换的案例,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
1.hover
移入其父元素.navI时,触发鼠标的hover态,给父元素添加样式为position:relative;z-index:1;。从而提升了层级z-index。在其子元素导航内容的层级比拼中,“子凭父贵”,父元素层级高的,其导航内容在重叠状态中显示在最上面
<style>body,p{margin: 0;}h3{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;}</style><div class="box"> <ul class="nav"> <li class="navI navI_active"> <h3 class="navI-tit">课程</h3> <p class="navI-txt">课程内容</p> </li> <li class="navI"> <h3 class="navI-tit">学习计划</h3> <p class="navI-txt ml1">学习计划内容</p> </li> <li class="navI"> <h3 class="navI-tit">技能图谱</h3> <p class="navI-txt ml2">技能图谱内容</p> </li> </ul> </div>
2.锚点
点击导航标题时,触发target伪类,改变对应的导航内容的层级z-index,从而使当前导航内容在三个导航内容中胜出,在最上层显示;与此同时,改变当前导航标题的样式
<style>body,p{margin: 0;}h3{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;}</style><div class="box"> <ul class="nav"> <li class="navI navI_active"> <p class="navI-txt" id="kc">课程内容</p> <a class="navI-tit" href="#kc">课程</a> </li> <li class="navI"> <p class="navI-txt ml1" id="xx">学习计划内容</p> <a class="navI-tit" href="#xx">学习计划</a> </li> <li class="navI"> <p class="navI-txt ml2" id="jn">技能图谱内容</p> <a class="navI-tit" href="#jn">技能图谱</a> </li> </ul> </div>
3.radio
点击导航标题时,触发checked伪类,改变对应的导航内容的层级z-index,从而使当前导航内容在三个导航内容中胜出,在最上层显示;与此同时,改变当前导航标题的样式
<style>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;}</style><div class="box"> <nav class="nav-tit"> <label class="nav-titI" for="kc">课程</label> <label class="nav-titI" for="xx">学习计划</label> <label class="nav-titI" for="jn">技能图谱</label> </nav> <nav class="nav-txt"> <input class="nav-txtI nav-txtI_active" id="kc" value="课程内容" readonly> <input class="nav-txtI" id="xx" value="学习计划内容" readonly> <input class="nav-txtI" id="jn" value="技能图谱内容" readonly> </nav></div>
感谢你能够认真阅读完这篇文章,希望小编分享的“CSS实现Tab页切换的案例”这篇文章对大家有帮助,同时也希望大家多多支持编程网,关注编程网精选频道,更多相关知识等着你来学习!
--结束END--
本文标题: CSS实现Tab页切换的案例
本文链接: https://lsjlt.com/news/253529.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0