作業(yè)分析
本次使用html與js樣式編寫效果如下

屏幕截圖 2025-03-27 192443.png

屏幕截圖 2025-03-27 192448.png
代碼實(shí)現(xiàn)
使用html代碼實(shí)現(xiàn)
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>shouye</title>
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
}
html {
font-size: 10px;
}
.bg {
display: flex;
justify-content: center;
height: 5rem;
width: 100%;
}
.content {
width: 120rem;
display: flex;
line-height: 5rem;
justify-content: space-evenly;
list-style: none;
font-size: 2rem;
font-weight: 30;
}
.content .item {
height: 100%;
padding: 0 5rem;
text-align: center;
cursor: pointer;
position: relative;
}
.content .item :hover {
background-color: aqua;
color: #000;
}
.chi {
list-style: none;
background-color: aqua;
position: absolute;
left: 0;
top: 5rem;
display: none;
}
.chi li {
padding: 1rem 2rem;
}
.chi li :hover {
background-color: aqua;
color: #000;
}
</style>
</head>
<body>
<div class="bg">
<ul class="content">
<li class="item">首頁</li>
<li class="item">文章
<ul class="chi">
<li>我的文章</li>
<li>發(fā)表文章</li>
</ul>
</li>
<li class="item">相冊(cè)
<ul class="chi">
<li>我的相冊(cè)</li>
<li>上傳照片</li>
</ul>
</li>
<li class="item">消息
<ul class="chi">
<li>我的私信</li>
<li>我的留言</li>
</ul>
</li>
</ul>
</div>
<script>
let lis = document.getElementsByClassName("item")
for (let i = 0; i < lis.length; i++) {
lis[i].onmouseenter = function () {
let child = lis[i].getElementsByClassName("chi")
if (child.length > 0) {
child[0].style.display = "block"
}
}
lis[i].onmouseleave = function () {
let child = lis[i].getElementsByClassName("chi")
if (child.length > 0) {
child[0].style.display = "none"
}
}
}
</script>
</body>
</html>
#個(gè)人總結(jié)
要熟練運(yùn)用使用js中函數(shù)的運(yùn)用,以及對(duì)定義的熟練掌握,同時(shí)對(duì)標(biāo)簽的仔細(xì)檢查