<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
li{
list-style: none;
}
a{
text-decoration: none;
}
.wrap{
width: 330px;
height: 30px;
margin: 100px auto 0;
padding-left: 10px;
background-image: url(../images/bg.jpg);
}
.wrap li{
background-image: url(../images/libg.jpg);
}
.wrap>ul>li{
float: left;
margin-right: 10px;
position: relative;
}
.wrap a{
display: block;
width: 100px;
height: 30px;
text-align: center;
line-height: 30px;
color: #000;
}
.wrap li ul{
position: absolute;
top: 30px;
left: 0;
display: none;
}
</style>
</head>
<body>
<div class="wrap">
<ul>
<li>
<a href="">一级菜单1</a>
<ul>
<li><a href="">二级菜单11</a></li>
<li><a href="">二级菜单12</a></li>
<li><a href="">二级菜单13</a></li>
</ul>
</li>
<li>
<a href="">一级菜单2</a>
<ul>
<li><a href="">二级菜单21</a></li>
<li><a href="">二级菜单22</a></li>
<li><a href="">二级菜单23</a></li>
</ul>
</li>
<li>
<a href="">一级菜单3</a>
<ul>
<li><a href="">二级菜单31</a></li>
<li><a href="">二级菜单32</a></li>
<li><a href="">二级菜单33</a></li>
</ul>
</li>
</ul>
</div>
<!-- 1.需要引入外部的jQuery文件 -->
<script type="text/javascript" src="../jquery-3.2.1.js"></script>
<script type="text/javascript">
$(function () {
$(".wrap>ul>li").mouseenter(function () {
$(this).children("ul").slideDown();
}).mouseleave(function () {
$(this).children("ul").slideUp(100);
})
})
</script>
</body>
</html>
上述运行结果: