当我将鼠标悬停在下拉菜单项上时,仅突出显示文本周围的部分,在菜单项的左侧留下未突出显示的空间。我需要更改什么才能使此效果覆盖下拉菜单项的整个宽度?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Get Connected | Sage Spiritual</title>
<link rel="stylesheet" href="sage.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans&family=Newsreader:[email protected]&display=swap');
html {
font-size: 62.5%;
scroll-behavior: smooth;
}
header {
font: 'Newsreader', Arial;
background-image: url(images/sparklebanner.jpg);
background-color: #7C8E93;
color: #292330;
font-size: 3.8rem;
text-align: center;
padding: 10px;
}
#logo {
float: left;
}
h1 {
font-family: 'Newsreader';
}
/*navigation-------------------*/
#navigation {
background-color: #EFE4DE;
font-size: 1.8rem;
border: 1px solid black;
}
nav {
background-color: #EFE4DE;
font-family: "Newsreader", Arial;
font-size: 1.8rem;
text-align: center;
max-width: 960px;
margin: 0 auto;
}
nav a:hover {
background-color: #ddd;
color: black;
border: 1px solid black;
}
#topnav {
list-style-type: none;
margin: 0;
padding: 0;
}
#topnav li {
display: inline-block;
position: relative;
font-size: 1.8rem;
}
#topnav li a {
display: block;
padding: 10px 20px;
color: #000;
text-decoration: none;
}
#topnav li ul {
display: none;
position: absolute;
top: 100%;
left: 0;
background-color: #F7F2EF;
}
#topnav li:hover > ul {
display: block;
}
#topnav li ul li {
display: block;
width: 100%;
}
#topnav li ul li ul {
display: none;
position: absolute;
top: 0;
left: 100%;
background-color: #F7F2EF;
}
#topnav li ul li:hover > ul {
display: block;
}
#topnav li ul li ul li {
display: block;
width: 100%;
}
</style>
</head>
<body>
<header>
<div id="logo"><a href="index.html"><img src="images/snake.png" width=120px height="175px" alt="sage spiritual snake logo" float="left"></a></div>
<h1><a href="index.html">Sage Spiritual</a></h1>
</header>
<!-- Top Navigation Bar -->
<div id="navigation"><nav>
<ul id="topnav">
<li><a href="index.html">Home</a></li>
<li>
<a href="magic.html">Magic</a>
</li>
<li>
<a href="spells.html">Spells</a>
<ul>
<li>
<a href="witches.html">Witches</a>
</li>
<li>
<a href="spellcasting.html">Spellcasting</a>
<ul>
<li><a href="energy.html">Energy</a></li>
<li><a href="altar.html">Altar</a></li>
</ul>
</li>
</ul>
</li>
<li>
<a href="tools.html">Significant Objects</a>
<ul>
<li>
<a href="candles.html">Candles</a>
</li>
<li>
<a href="crystals.html">Crystals</a>
</li>
<li>
<a href="pantry.html">Pantry</a>
</li>
</ul>
</li>
<li>
<a href="divination.html">Divination</a>
</li>
<li>
<a href="timing.html">Timing & Cycles</a>
<ul>
<li>
<a href="holidays.html">Holidays</a>
</li>
<li>
<a href="cosmic.html">Cosmic</a>
<ul>
<li><a href="mooncycles.html">Moon Cycles</a></li>
<li><a href="astro.html">Astrological Seasons</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav></div>
我尝试过使用填充和显示属性,但没有任何效果。
为了解决这个问题,我对您的CSS代码做了一些调整。具体来说,我修改了 #topnav li ul li 选择器,以确保将鼠标悬停在下拉菜单项上时覆盖整个宽度。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Get Connected | Sage Spiritual</title>
<link rel="stylesheet" href="sage.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans&family=Newsreader:[email protected]&display=swap');
html {
font-size: 62.5%;
scroll-behavior: smooth;
}
header {
font: 'Newsreader', Arial;
background-image: url(images/sparklebanner.jpg);
background-color: #7C8E93;
color: #292330;
font-size: 3.8rem;
text-align: center;
padding: 10px;
}
#logo {
float: left;
}
h1 {
font-family: 'Newsreader';
}
/* Navigation */
#navigation {
background-color: #EFE4DE;
font-size: 1.8rem;
border: 1px solid black;
}
nav {
background-color: #EFE4DE;
font-family: "Newsreader", Arial;
font-size: 1.8rem;
text-align: center;
max-width: 960px;
margin: 0 auto;
}
nav a:hover {
background-color: #ddd;
color: black;
border: 1px solid black;
}
#topnav {
list-style-type: none;
margin: 0;
padding: 0;
}
#topnav li {
display: inline-block;
position: relative;
font-size: 1.8rem;
}
#topnav li a {
display: block;
padding: 10px 20px;
color: #000;
text-decoration: none;
}
#topnav li ul {
display: none;
position: absolute;
top: 100%;
left: 0;
background-color: #F7F2EF;
}
#topnav li:hover > ul {
display: block;
}
#topnav li ul li {
display: block;
width: 100%;
}
#topnav li ul li a {
display: block;
padding: 10px 20px;
color: #000;
text-decoration: none;
}
#topnav li ul li:hover > a {
background-color: #ddd;
color: black;
}
#topnav li ul li ul {
display: none;
position: absolute;
top: 0;
left: 100%;
background-color: #F7F2EF;
}
#topnav li ul li:hover > ul {
display: block;
}
#topnav li ul li ul li {
display: block;
width: 100%;
}
</style>
</head>
<body>
<header>
<div id="logo"><a href="index.html"><img src="images/snake.png" width="120px" height="175px" alt="sage spiritual snake logo"></a></div>
<h1><a href="index.html">Sage Spiritual</a></h1>
</header>
<!-- Top Navigation Bar -->
<div id="navigation">
<nav>
<ul id="topnav">
<li><a href="index.html">Home</a></li>
<li>
<a href="magic.html">Magic</a>
</li>
<li>
<a href="spells.html">Spells</a>
<ul>
<li>
<a href="witches.html">Witches</a>
</li>
<li>
<a href="spellcasting.html">Spellcasting</a>
<ul>
<li><a href="energy.html">Energy</a></li>
<li><a href="altar.html">Altar</a></li>
</ul>
</li>
</ul>
</li>
<li>
<a href="tools.html">Significant Objects</a>
<ul>
<li>
<a href="candles.html">Candles</a>
</li>
<li>
<a href="crystals.html">Crystals</a>
</li>
<li>
<a href="pantry.html">Pantry</a>
</li>
</ul>
</li>
<li>
<a href="divination.html">Divination</a>
</li>
<li>
<a href="timing.html">Timing & Cycles</a>
<ul>
<li>
<a href="holidays.html">Holidays</a>
</li>
<li>
<a href="cosmic.html">Cosmic</a>
<ul>
<li><a href="mooncycles.html">Moon Cycles</a></li>
<li><a href="astro.html">Astrological Seasons</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</div>
</body>
</html>
请使用此更新的代码。如果您需要进一步帮助或有任何疑问,请告诉我。