作业分析
本次使用html与js样式编写效果如下

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

屏幕截图 2025-03-27 192448.png
代码实现
使用html代码实现
<!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>发表文章</li>
</ul>
</li>
<li class="item">相册
<ul class="chi">
<li>我的相册</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>
#个人总结
要熟练运用使用js中函数的运用,以及对定义的熟练掌握,同时对标签的仔细检查