<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/*兼容浏览器*/
*{
padding: 0;
margin: 0;
}
.content{
width: 100%;
height: 100%;
}
.content-left{
width: 19%;
height: 800px;
background-color: #1c232f;
/* 左浮动 */
float: left;
}
.content-right{
width: 81%;
height: 800px;
background-color: #6495ED;
/* 右浮动 */
float: right;
}
.left-title{
height: 50px;
width: 100%;
}
.left-title>a{
display: block;
width: 100%;
height: 50;
/* 垂直居中 */
line-height: 50px;
/* 水平居中 */
text-align: center;
color: white;
text-decoration: none;
}
/* 分隔线 */
.seg{
height: 1px;
width: 100%;
background-color: black;
}
.nav{
/* 调整与上一个标签的距离 */
margin: 5px 0;
}
/* 菜单项主标题 */
.nav-title{
height: 40px;
width: 100%;
color: white;
text-align: center;
line-height: 40px;
cursor: pointer;
}
.nav-content{
width: 100%;
height: 100%;
background-color: #0c1119;
}
.nav-content>a{
display: block;
height: 30px;
width: 100%;
color: #cccccc;
text-align: center;
line-height: 30px;
text-decoration: none;
font-size: 14px;
}
/* 给标签添加伪类 */
.nav-content>a:hover{
display: block;
height: 30px;
width: 100%;
color: #ffffff;
text-align: center;
line-height: 30px;
background-color: #12040c;
text-decoration: none;
}
</style>
<script src="../jquery.min.js"></script>
<script>
/*加载函数*/
$(function(){
//隐藏所有的子标题
$('.nav-menu').each(function(){
$(this).children('.nav-content').hide();
})
//给所有的菜单项的主标题添加事件
$('.nav-title').each(function(){
$(this).click(function(){
//当点击主标题时,子标题区展示出来
//获取当下的子标题内容区
var navConEle= $(this).parent('.nav-menu').children('.nav-content');
//判断navConEle的对象display 这个属性的值是否为none
if(navConEle.css('display')!='none'){
//隐藏
navConEle.hide(500);
}
else
{
/*当要展开一个子标题列表 的时候需要将其它的孺子标题关闭*/
var conEle=navConEle.parents('.nav-menu');
var menuEles=conEle.siblings();
menuEles.each(function(){
$(this).children('.nav-content').hide();
})
//展开
navConEle.show(500);
}
})
})
});
</script>
</head>
<body>
<div class="content">
<div class="content-left">
<div class="left-title">
<a href="#">XX后台</a>
</div>
<div class="seg"></div>
<!-- 菜单栏导航 -->
<div class="nav">
<!-- 每一个菜单栏项 -->
<div class="nav-menu">
<!-- 主标题 -->
<div class="nav-title">商品管理</div>
<!-- 子标题 -->
<div class="nav-content">
<a href="#">商品列表</a>
<a href="#">添加商品</a>
</div>
</div>
<!-- 每一个菜单栏项 -->
<div class="nav-menu">
<!-- 主标题 -->
<div class="nav-title">订单管理</div>
<!-- 子标题 -->
<div class="nav-content">
<a href="#">订单列表</a>
<a href="#">添加订单</a>
</div>
</div>
<!-- 每一个菜单栏项 -->
<div class="nav-menu">
<!-- 主标题 -->
<div class="nav-title">类目管理</div>
<!-- 子标题 -->
<div class="nav-content">
<a href="#">类目列表</a>
<a href="#">添加类目</a>
</div>
</div>
</div>
<div class="seg"></div>
</div>
<div class="content-right">
<h1>内容区</h1>
</div>
</div>
</body>
</html>