* { margin:0; padding:0; } .clearfix { zoom:1; } .clearfix:after { content:"."; display:block; width:0; height:0; visibility:hidden; clear:both; } .container { margin:20px; } ul { list-style:none; padding-left:20px; } ul li { float:left; padding:5px 10px; text-align:center; border:1px solid #ccc; border-bottom:0; } .con { display:none; width:300px; border:1px solid #ccc; height:200px; text-align:center; } ul li.sel { background-color:red; } .con.sel { display:block; }
思路:本例中添加的是鼠标经过事件,可以将mouseover换成click事件
循环导航中的li,给li添加事件,获取当前li的索引值,通过给内容项添加class名sel