.wrap{
box-sizing: border-box;
width: 500px;
margin: 50px auto;
}
/*清浮动---clearfix*/
.clearfix {
*zoom: 1;
}
.clearfix:after {
content: "";
clear: both;
display: block;
height: 0;
font-size: 0;
visibility: hidden;
}
.list {
border:1px solid #d9d9d9;
width: 100%;
height: 33px;
box-sizing: border-box;
}
.list li:first-child{
border-left: none;
}
.list li{
list-style: none;
width: 25%;
height: 32px;
border-left:1px solid #d9d9d9;
font-size: 14px;
font-family: "楷体";
line-height: 32px;
text-align: center;
float: left;
/*鼠标样式改变为一个手*/
cursor: pointer;
/*字体免选中*/
-webkit-user-select: none;
box-sizing: border-box;
}
.list-item{
width: 100%;
}
.list-item li{
list-style: none;
width: 100%;
border:1px solid #ccc;
height: 200px;
border-top: none;
padding:8px 10px;
box-sizing: border-box;
}
.wrap .list li.active{
font-weight: bold;
color: red;
border-top: 2px solid red;
position: relative;
top:-1px;
height: 31px;
}
.list-item li:first-child{
display: block;
}
.list-item li{
display: none;
}
<div class="wrap">
<ul class="list clearfix list-on">
<li class="active">HTML</li>
<li>C#</li>
<li>JAVA</li>
<li>PHP</li>
</ul>
<ul class="list-item">
<li>苏飞论坛-前端</li>
<li>苏飞论坛-C#</li>
<li>苏飞论坛-JAVA</li>
<li>苏飞论坛-PHP</li>
</ul>
</div>
$(".list-on").on("click","li",function(){
// 设index为当前点击
var index = $(this).index();
// 点击添加样式利用siblings清除其他兄弟节点样式
$(this).addClass("active").siblings().removeClass("active");
// 同理显示与隐藏
$(this).parents(".wrap").find(".list-item li").eq(index).show().siblings().hide();
})
欢迎光临 苏飞论坛 (http://www.sufeinet.com/) | Powered by Discuz! X3.4 |