gpt4 book ai didi

HTML/CSS 下拉菜单 : The second list item in my code is overlapping the first

转载 作者:太空宇宙 更新时间:2023-11-04 10:48:48 24 4
gpt4 key购买 nike

我正在制作一个仅使用 HTML 和 CSS 的下拉菜单。菜单组件成功下降,一切看起来都很好,除非一个元素有两个或更多组件。然后第二个覆盖第一个。我可以通过在“#nav ul li:hover ul”(下面的代码)中放置“position: absolute”来解决这个问题,但是第一个元素不会清除菜单栏。

对于糟糕的描述,我们深表歉意。

    <!DOCTYPE HTML>
<html>
<head>
<link type="text/css" rel="stylesheet" href="CSS/index.css" />
<title>Index</title>
</head>
<body background="Images/Sun.jpg">
<div class="center" id="main">
<div class="center" id="header">
<br/><p>JOSEPH T. IOSUE</p><br/>
</div>
<div class="center" id="nav">
<ul>
<li><a href="index.html">HOME</a></li>
<li><a href="#">ABOUT ME</a></li>
<li><a href="#">PROJECTS</a>
<ul>
<li><a href="#">PYTHON</a></li>
<li><a href="#">HTML/CSS</a></li>
</ul>
</li>
<li><a href="#" download>RESUME</a></li>
<li><a href="#">CONTACT</a>
<ul>
<li><a href="#">joe.iosue@yahoo.com</a></li>
<li><a href="#">301-980-9525</a></li>
</ul>
</li>
</ul>
</div>
<div style="background-color:white;clear:both;background-color:#00CCFF">
</div>
</div>
</body>
</html>

这是CSS

body {
background-size: 100%;
background-repeat: no-repeat;
}
#main {
background-color: #00CCFF;
width: 70%;
}
ul {
list-style: none;
}
#header {
width: 100%;
background-color: blue;
text-align: center;
}
#header p {
font-size: 3vw;
font-weight: bold;
}
#header * {
margin: 0px 0px 0px 0px;
}
#nav {
width: 100%;
}
#nav * {
margin: 0px 0px 0px 0px;
display: block;
float: left;
font-size: 1vw;
border: 0px 0px 0px 0px;
background-color: #00CCFF;
}
#nav a {
text-decoration: none;
background-color: #00CCFF;
padding: 1vw 3vw 1vw 3vw;
}
#nav ul li {
position: relative;
}
#nav ul li a {
color: white;
font-weight: bold;
}
#nav ul li ul {
display: none;
}
#nav ul li:hover ul {
display: block;
float: none;
clear: both;
}
#nav ul li:hover ul li a {
position: absolute;
background-color: #ff0000;
}
#nav ul li:hover ul li a:hover {
background-color: #ff6666;
}
.center {
margin: auto;
}

最佳答案

请检查以下代码。我稍微修改了你的 CSS。

body {
background-size: 100%;
background-repeat: no-repeat;
}
#main {
background-color: #00CCFF;
width: 70%;
}
ul {
list-style: none;
}
#header {
width: 100%;
background-color: blue;
text-align: center;
}
#header p {
font-size: 3vw;
font-weight: bold;
}
#header * {
margin: 0px 0px 0px 0px;
}
#nav {
width: 100%;
}
#nav * {
margin: 0px 0px 0px 0px;
display: block;
float: left;
font-size: 1vw;
border: 0px 0px 0px 0px;
background-color: #00CCFF;
}
#nav a {
text-decoration: none;
background-color: #00CCFF;
padding: 1vw 3vw 1vw 3vw;
}
#nav ul li {
position: relative;
}
#nav ul li a {
color: white;
font-weight: bold;
}
#nav ul li ul {
display: none;
position: absolute;
top:100%;
left: 0;
padding: 0;
background-color: #ff0000;
}
#nav ul li:hover ul {
display: block;
}
#nav ul li ul li{
background: none;
float: none;
display: block;
}
#nav ul li ul li a {
display: block;
float: none;
background-color: #ff0000;
}
#nav ul li ul li a:hover {
background-color: #ff6666;
}
.center {
margin: auto;
}
<div class="center" id="main">
<div class="center" id="header">
<br/><p>JOSEPH T. IOSUE</p><br/>
</div>
<div class="center" id="nav">
<ul>
<li><a href="index.html">HOME</a></li>
<li><a href="#">ABOUT ME</a></li>
<li><a href="#">PROJECTS</a>
<ul>
<li><a href="#">PYTHON</a></li>
<li><a href="#">HTML/CSS</a></li>
</ul>
</li>
<li><a href="#" download>RESUME</a></li>
<li><a href="#">CONTACT</a>
<ul>
<li><a href="#">joe.iosue@yahoo.com</a></li>
<li><a href="#">301-980-9525</a></li>
</ul>
</li>
</ul>
</div>
<div style="background-color:white;clear:both;background-color:#00CCFF">
</div>
</div>

关于HTML/CSS 下拉菜单 : The second list item in my code is overlapping the first,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35145686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com