<!DOCTYPE html>
<html>
<head>
<title>BHSS Solar Racing</title>
<meta charset='utf-8'/>
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
</head>
<body>
<p>
<div>Bloomington High School South</div>
<div>Solar Racing Team</div>
</p>
<p>
<div>Helionauts</div>
</p>
<!--Team-->
<p>
<div>
</div>
</p>
<!--Sponsors-->
<p>
<div>
</div>
</p>
<!--History-->
<p>
<div>
</div>
</p>
<!--Vehicles-->
<p>
<div>
</div>
</p>
<!--Donate-->
<p>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Donate</a>
<ul>
<li><a href="#">Sponsorship Perks</a></li>
<li><a href="#">Payment Information</a></li>
</ul>
</li>
<li><a href="#">Articles</a>
<ul>
<li><a href="#">Web Design</a></li>
<li><a href="#">User Experience</a></li>
</ul>
</li>
<li><a href="#">Inspiration</a></li>
</ul>
</nav>
</p>
</body>
</html>
//这是css代码
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
background: #000000;
background: linear-gradient(top, #000000 0%, #000000 100%);
background: -moz-linear-gradient(top, #000000 0%, #000000 100%);
background: -webkit-linear-gradient(top, #000000 0%,#000000 100%);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
padding: 0 20px;
border-radius: 0px;
list-style: none;
position: relative;
left:640px;
display: inline-table;
}
nav ul:after {
content: ""; clear: both; display: block;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: #4b545f;
background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%);
}
nav ul li:hover a {
color: #fff;
}
nav ul li a {
display: block; padding: 25px 40px;
color: #FFFFFF; text-decoration: none;
}
nav ul ul {
background: #5f6975; border-radius: 0px; padding: 0;
position: relative; top: 100%;
left:0px;
}
nav ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a;
position: relative;
}
nav ul ul li a {
padding: 15px 40px;
color: #fff;
}
nav ul ul li a:hover {
background: #4b545f;
}
nav ul ul ul {
position: absolute; left: 100%; top:0;
}
答案 0 :(得分:0)
这里的问题是,由于您的子菜单嵌套在主菜单中,因此无论何时显示子菜单,父菜单都必须展开以为子菜单腾出空间。这种扩张正在通过出现的额外黑色空间来说明。
此处的解决方案是从最顶层ul
中删除背景,然后将其应用于直接子项li
。
我已使用以下内容替换了您的nav ul
CSS规则集:
nav > ul > li {
background: #000000;
background: linear-gradient(top, #000000 0%, #000000 100%);
background: -moz-linear-gradient(top, #000000 0%, #000000 100%);
background: -webkit-linear-gradient(top, #000000 0%, #000000 100%);
box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15);
}
nav ul {
padding: 0 20px;
list-style: none;
position: relative;
left:640px;
display: inline-table;
}
请注意,有关背景或边框的所有规则都已移至li
。