使用工具 VsCode
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>下拉菜單</title>
<style>
*{margin: 0;padding: 0;box-sizing: border-box;}
html,body{height: 100%;height: 100%;}
html,
body{
width: 100%;
height: 100%;
}
html{
font-size: 10px;
}
.nav{
width: 100%;
height: 5rem;
background-color: azure;
display: flex;
justify-content: center;
}
.content{
width: 120rem;
list-style: none;
display: flex;
}
.content .item{
font-size: 1.8rem;
height: 100%;
padding: 0 5rem;
text-align: center;
line-height: 5rem;
cursor: pointer;
position: relative;
}
.content .content:hover{
background-color: aliceblue;
color: #333;
}
.children{
list-style: none;
background-color: antiquewhite;
position: absolute;
left: 0;
top: 5rem;
display: none;
}
.children li{
padding: 1rem 2rem;
}
.children li:hover{
background-color: beige;
color: #333;
}
</style>
</head>
<body>
<div class="nav">
<div class="content">
<li class="item">首頁</li>
<li class="item">文章
<ul class="children">
<li>我的文章</li>
<li>發(fā)表文章</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>
</div>
</div>
<script>
function toggleMenu(parent,is_show){
let child=parent.getElementsByClassName("children")
if(child.length>0){
child[0].style.display=is_show
}
}
let_lis=document.getElementsByClassName("item")
for(let i=0;i<_lis.length;i++){
_lis[i].onmouseenter=function(){
toggleMenu(_lis[i],"block")
}
_lis[i].onmouseleave=function(){
toggleMenu(_lis[i],"none")
}
}
</script>
</body>
</html>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。