<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
}
.nav {
width: 1500px;
height: 40px;
background-color: rgb(132, 204, 180);
display: flex;
justify-content: center;
}
.content {
width: 600px;
height: 40px;
background-color: rgb(185, 255, 232);
display: flex;
}
.content .item {
height: 40px;
width: 600px;
text-align: center;
line-height: 40px;
background-color: rgb(53, 173, 133);
}
li {
list-style: none;
border-right: 1px solid #fff;
}
.children {
background-color: rgb(90, 189, 156);
}
.content .item{
position: relative;
}
.children{
position: absolute;
display: none;
}
.children li{
width: 150px;height: 100%;
}
</style>
<body>
<div class="nav">
<ul class="content">
<li class="item">首页</li>
<li class="item">文章
<ul class="children">
<li>我的文章</li>
<li>发表文章</li>
</ul>
</li>
<li class="item">相册
<ul class="children">
<li>我的相册</li>
<li>上传照片</li>
</ul>
</li>
<li class="item">消息
<ul class="children">
<li>我的私信</li>
<li>我的留言</li>
</ul>
</li>
</ul>
</div>
<script>
let menu1 = document.getElementsByClassName("item")
for (let i = 0; i < menu1.length; i++) {
menu1[i].onmouseenter = function () {
console.log("用户进入了", i, "的菜单")
let child = menu1[i].getElementsByClassName("children")
if (child.length > 0) {
child[0].style.display = "block"
}
}
menu1[i].onmouseleave = function () {
let child = menu1[i].getElementsByClassName("children")
if (child.length > 0) {
child[0].style.display = "none"
}
}
}
</script>
</body>
</html>
下拉菜单
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- html下拉菜单怎么做?html下拉菜单代码是什么?这些对于刚刚入门的新手,还不是很明白,下面高手教你如何在HTM...
- 前些天有同事在制作员工信息登记表的时候,将家庭地址拆分为“省”“市”“区(县)”时,一项项的设置下拉菜单,这样操作...
- BootStrap下拉菜单 .dropdown 菜单用于指定下拉菜单,下拉菜单都包裹在 .dropdown 里。 ...
- 一。 select * from fenxiao_jiekou_baiping_daioyong_statis a...