html - 导航中的背景边框问题
问题描述
我在将背景颜色一次性应用于导航部分的一部分页面方面遇到了一些麻烦。目前,当我将鼠标悬停在黄铜上时,背景颜色将应用于黄铜和本节中的页面。我想要完成的是让背景颜色仅在我将鼠标悬停在这些元素上而不是一次全部出现时出现。
header {
color: #348899;
background-color: #343642;
background-image: url(Images/heading.png);
background-position: right;
background-repeat: no-repeat;
}
#wrapper {
width: 90%;
margin-right: auto;
margin-left: auto;
}
h1 {
margin: 0;
padding: 10px;
font-size: 42pt;
line-height: 36pt;
font-weight: lighter;
}
h2 {
margin: 0;
padding: 0 10px 5px;
font-size: 18pt;
line-height: 22pt;
font-weight: bold;
font-style: italic;
}
h3 {
margin: 0;
padding: 0 10px 5px 0;
font-size: 18pt;
line-height: 22pt;
font-weight: bold;
font-style: italic;
}
nav {
color: #343642;
background-color: #979C9C;
float: left;
width: 160px;
font-weight: bold;
height: 100%;
}
nav ul li {
list-style: none;
padding: 10px;
}
nav ul li:hover {
background-color: #b1b6b6;
}
nav ul li a {
display: block;
text-decoration: none;
color: #343642;
}
nav ul li ul {
display: none;
position: relative;
left: auto;
right: 35%;
}
nav ul li:hover ul {
display: block;
}
nav ul li ul li a:hover {
color: #fff;
}
nav ul li a:hover {
color: #fff;
}
main {
color: #17354A;
background-color: #F2EBC7;
margin-left: 160px;
padding: 10px;
z-index: 0;
display: flex;
}
.column {
float: left;
}
.left {
width: 75%;
}
.right {
width: 25%;
}
.text {
font-size: 25px;
margin: 0 20px 0 0;
}
main .row .left {
width: 25%;
}
main .row .middle {
width: 50%;
}
main .row .right {
width: 25%;
}
.brass {
float: right;
margin: 0 0 5px 5px;
}
.logo {
float: right;
margin: 0 0 5px 5px;
}
body{
background-color: #348899;
font-family: Calibri, Helvetica, Arial, Sans-Serif;
}
footer {
color: #348899;
background-color: #343642;
font-style: italic;
text-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="project.css">
<meta charset="utf-8" />
<title>Beginning Band Players - Home</title>
</head>
<body>
<div id="wrapper">
<header>
<h1>
Beginning Band Players
</h1>
<h2>
Home
</h2>
</header>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="#">Brass</a>
<ul>
<li><a href="Brass/trumpet.html">Trumpet</a></li>
<li><a href="Brass/frenchhorn.html">Horn</a></li>
<li><a href="Brass/trombone.html">Trombone</a></li>
<li><a href="Brass/euphonium.html">Euphonium</a></li>
<li><a href="Brass/tuba.html">Tuba</a></li>
</ul>
</li>
<li><a href="#">Woodwind</a>
<ul>
<li><a href="Woodwind/clarinet.html">Clarinet</a></li>
<li><a href="Woodwind/flute.html">Flute</a></li>
<li><a href="Woodwind/oboe.html">Oboe</a></li>
<li><a href="Woodwind/saxophone.html">Saxophone</a></li>
</ul>
</li>
<li><a href="#">Percussion</a>
<ul>
<li><a href="Percussion/bells.html">Bells</a></li>
<li><a href="Percussion/snare.html">Snare Drum</a></li>
</ul>
</li>
<li><a href="#">Maintenence</a></li>
<li><a href="#">Additional Equipment</a></li>
</ul>
</nav>
<main>
<div class="column left">
<div class="logo">
<img src="Images/Logo-E.png" alt="logo" height="200" width="355">
</div>
<h3>
About us:
</h3>
<div class="text">
<p>
The purpose of Beginning Band Players is to provide students and parents
with the necessary resources for a successful start in any band program.
It's our hope that prospective music students find what they're looking
for and enjoy a lifetime of music.
</p>
<div class="brass">
<img src="Images/brass-1.jpg" alt="brass" height="238" width="425">
</div>
</div>
</div>
<div class="column right">
<h3>
What to Expect:
</h3>
<p>
Students can learn a little about each instrument found in beginning band
programs and decide which one they like best. They'll be able to see and
hear what each instrument sounds like.
</p>
<h3>
Additional Resources:
</h3>
<p>
Students may also need additional equipment such as practice books or supplies
to help maintain their instruments. Links to such supplies can be found on the
Additional Equipment page.
</p>
</div>
</main>
<footer>
Copyright © 2022, Carter Thomas Wolfe <br>
Web Project Prototype
</footer>
</div>
</body>
</html>
解决方案
你可以用这个
nav ul li ul li:hover {
background-color: #b1b6b6;
}
代替
nav ul li:hover {
background-color: #b1b6b6;
}
推荐阅读
- python - 在 Dask 的多处理中,方法被调用两次而不是一次调用
- java - 针对字符串类型的 XSD nillable false 的 XML 验证
- android - 如何摆脱或隐藏“NFC检测通知”和“使用弹出窗口完成操作”?
- flutter - 如何在颤动中同时换行和缩小文本?
- unit-testing - 如何在 Rust 中运行任何测试之前运行设置代码?
- php - 如何检查值一个数组元素是否完全存在于另一个数组中并在php中创建新数组作为不同数组值的容器
- python - 使用python将多个未排序的文本文件合并为一个排序文件
- javascript - 如何从 ng2 智能表中的 API 获取数据?
- ios - 我可以在 XCode 的故事板编辑器中指定一个目标吗?
- sql-server - 导入具有多个分隔符的平面数据