<!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>
/* 232 */
.xlcd{
border: 2px solid green;
height: 150px;
}
.first .ab{
border: 2px solid rgb(179, 176, 28) ;
padding-left: 40px;
padding-right: 40px;
}
.main .first{
float: left;
}
ul a{
text-decoration: none;
}
ul li{
display: flex;
flex-direction: column;
/* border: 1px solid yellow; */
list-style-type: none;
}
ul li ul li:hover{
background-color: rgb(223, 186, 92);
color: aliceblue;
}
.main ul{
display: none;
border: 1px solid gold;
}
</style>
</head>
<body>
<!-- 下拉菜单 -->
<div class="xlcd">
<ul class="main">
<li class="first">
<a href="#" class="ab">微博</a>
<ul>
<li><a href="#">私信</a></li>
<li><a href="#">评论</a></li>
<li><a href="#">@我</a></li>
</ul>
</li>
<li class="first">
<a href="#" class="ab">微博</a>
<ul>
<li><a href="#">私信</a></li>
<li><a href="#">评论</a></li>
<li><a href="#">@我</a></li>
</ul>
</li>
<li class="first">
<a href="#" class="ab">微博</a>
<ul>
<li><a href="#">私信</a></li>
<li><a href="#">评论</a></li>
<li><a href="#">@我</a></li>
</ul>
</li>
</ul>
</div>
<script>
// 1.获取元素
var main = document.querySelector('.main');
var lis = main.children;//得到小li
for (var i = 0; i < lis.length; i++){
lis[i].onmouseover = function(){
this.children[1].style.display = 'block';
}
lis[i].onmouseout = function(){
this.children[1].style.display = 'none';
}
}
</script>
</body>
</html>