我想為我正在制作的網站設置一個固定標題下的水平導航欄的格式。我可以這樣做,但現在懸停效果不起作用。我的意思是,只有當我將光標對準導航欄的底部邊緣,鏈接就在它的正上方時,懸停效果才起作用。當光標懸停在文本上時,我希望懸停效果起作用。請幫幫忙!!謝謝大家!
@import url(https://fonts.googleapis.com/css?family=Raleway);
body {
margin: 0;
padding: 0;
}
/* all header stuff*/
header {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 80px;
background-color: #c7c7c7;
padding: 20px;
display: flex;
align-items: center;
box-shadow: 0 0 10px rgba(0, 0, 0, 1.0);
z-index: 999; /* Ensure the header is above the other elements */
}
.logo-container {
display: flex;
align-items: center;
}
.logo {
width: 210px; /* Adjust width as needed */
height: auto;
margin-right: 10px; /* Adjust margin as needed */
}
.title {
margin-bottom: 5px;
font-family: 'Raleway', arial, sans-serif;
font-size: 40px;
}
.subheading {
font-family: 'Raleway', arial, sans-serif;
font-size: 24px;
margin-top: 5px;
}
/*all nav bar stuff*/
nav {
background-color: #c7c7c7;
height: 40px;
margin-top: 120px;
}
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
text-align:center;
font-family: 'Raleway', arial, sans-serif;
font-size: 20px;
}
nav li {
display: inline-block;
margin-left: 10px;
margin-right: 10px;
}
nav li a {
display: block;
color: #333;
text-decoration: none;
padding: 10px;
}
nav li a:hover {
color: #f45c2c;
text-decoration: underline;
}
<!DOCTYPE html>
<html>
<head>
<title>Bioreactor</title>
<link href="Bioreactor.css" rel="stylesheet" type="text/css">
</head>
<body>
<header>
<div class="logo-container">
<img src="logo.png" alt="Logo" class="logo">
<div>
<h1 class="title">PAK BioSolutions Process Design | Home</h1>
<h3 class = "subheading">Driving Advancements in Biopharmaceutical Manufacturing</h3>
</div>
</div>
</header>
<nav>
<ul>
<li><a href="Bioreactor.html">Bioreactor</a></li>
<li><a href="Chromatography.html">Chromatography</a></li>
<li><a href="Virus Inactivation.html">Virus Inactivation</a></li>
<li><a href="0.2 Micron Filtration.html">0.2 Micron Filtration</a></li>
<li><a href="Virus Filtration.html">Virus Filtration</a></li>
</ul>
</nav>
</body>
</html>
嘗試將ul元素放在阿利導航中:懸停它應該可以工作
你應該把導航放在標題里面
@import url(https://fonts.googleapis.com/css?family=Raleway);
body {
margin: 0;
padding: 0;
}
/* all header stuff*/
header {
position: fixed;
/* top: 0; */
/* left: 0; */
width: 100%;
/* height: 80px; */
background-color: #c7c7c7;
/* padding: 20px; */
/* display: flex; */
/* align-items: center; */
box-shadow: 0 0 10px rgba(0, 0, 0, 1.0);
z-index: 999; /* Ensure the header is above the other elements */
}
.logo-container {
display: flex;
align-items: center;
}
.logo {
width: 210px; /* Adjust width as needed */
height: auto;
margin-right: 10px; /* Adjust margin as needed */
}
.title {
margin-bottom: 5px;
font-family: 'Raleway', arial, sans-serif;
font-size: 40px;
}
.subheading {
font-family: 'Raleway', arial, sans-serif;
font-size: 24px;
margin-top: 5px;
}
/*all nav bar stuff*/
nav {
background-color: #c7c7c7;
/* height: 40px; */
/* margin-top: 120px; */
}
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
text-align:center;
font-family: 'Raleway', arial, sans-serif;
font-size: 20px;
}
nav li {
display: inline-block;
margin-left: 10px;
margin-right: 10px;
}
nav li a {
display: block;
color: #333;
text-decoration: none;
padding: 10px;
}
nav li a:hover {
color: #f45c2c;
text-decoration: underline;
}
<header>
<div class="logo-container">
<img src="" alt="Logo" class="logo">
<div>
<h1 class="title">PAK BioSolutions Process Design | Home</h1>
<h3 class="subheading">Driving Advancements in Biopharmaceutical Manufacturing</h3>
</div>
</div>
<nav>
<ul>
<li><a href="Bioreactor.html">Bioreactor</a></li>
<li><a href="Chromatography.html">Chromatography</a></li>
<li><a href="Virus Inactivation.html">Virus Inactivation</a></li>
<li><a href="0.2 Micron Filtration.html">0.2 Micron Filtration</a></li>
<li><a href="Virus Filtration.html">Virus Filtration</a></li>
</ul>
</nav>
</header>