有人能帮帮我为什么会这样吗?
我正在为我的大学作业创建网站,当我试图创建固定响应导航栏时,我遇到了这个问题。 当我向下滚动时,身体内容如或将与固定导航栏重叠。
[这是它如何与固定条重叠的示例图片][1]
下面是我的HTML代码:
<html lang= "en">
<head>
<meta charset="utf-8">
<title>Tanat Resort</title>
<meta name="viewport" content="width=device-width, initial-scale= 1">
<link rel="stylesheet" href="css/style.css"/>
<script src="js/jquery-3.5.1.min.js"></script>
<script src="js/main.js"></script>
</head>
<body>
<nav class="navbar">
<a href="index.html" class="logo">TANAT RESORT</a>
<ul class="desktop-list">
<li class="desktop-menu"><a href="resident.html">Resident</a></li>
<li class="desktop-menu"><a href="event.html">event</a></li>
<li class="desktop-menu"><a href="more.html">More..</a></li>
<li class="desktop-menu" id="book-button"><a href="#" id="book-menu">Book now</a></li>
</ul>
<a href="#" class="burger-menu" onclick="myFunction(this)">
<div class="menulogo1"></div>
<div class="menulogo2"></div>
<div class="menulogo3"></div>
</a>
<ul id="responsive-menu">
<li class="hidden-menu"><a href="index.html">Home</a></li>
<li class="hidden-menu"><a href="resident.html">Resident</a></li>
<li class="hidden-menu"><a href="event.html">event</a></li>
<li class="hidden-menu"><a href="more.html">More..</a></li>
<li class="hidden-menu"><a href="more.html">About us</a></li>
<li class="hidden-menu"><a href="#">Contact</a></li>
</ul>
</nav>
<section id="search-bar">
Search bar here
</section>
<article>
<section class="main-article">
<h1>Discover the most adventurous resort in the world</h1>
<h1>Tanat's Resort</h1>
</section>
<section class="main-galleries">
<img class = "banner-img" src="images/beach-top-view.jpg" alt="beach">
<article class="gallery-articles">
<h2>Experience</h2>
<p>Beach, ocean, volcano. </p>
<a href="#" class="more-buttons">DISCOVER MORE</a>
</article>
</section>
<section class="main-galleries">
<img class = "banner-img" src="images/bird-s-eye-view-photo-of-cabanas-1456293.jpg" alt="resort view from top">
<article class="gallery-articles">
<h2>Our resident</h2>
<p>"Would you like to buy a vowel?" printed on the front. He listens carefully to Mark’s diagnosis. Then he unshoulders his heavy hoe and starts digging.</p>
<a href="#" class="more-buttons">DISCOVER MORE</a>
</article>
</section>
<section class="main-galleries">
<img class = "banner-img" src="images/lava-flowing-1687530.jpg" alt="lava flowing picture">
<article class="gallery-articles">
<h2>Activities</h2>
<p>Test 12345</p>
<a href="#" class="more-buttons">DISCOVER MORE</a>
</article>
</section>
<article id="slide-galleries">
<p>Slide Galleries</p>
</article>
</article>
<footer>
<section>
<p>Footer</p>
<p>Footer</p>
<p>Footer</p>
<p>Footer</p>
<p>Footer</p>
</section>
</footer>
</body>
</html>```
and CSS code (I only provide the responsive css code)
@media screen and (max-width: 768px) {
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
overflow-x:hidden;
}
.navbar {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
background-color: white;
list-style-type: none;
position: fixed;
top: 0;
width: 100%;
border-bottom-style: solid;
border-color: grey;
}
a {
display: block;
color: black;
text-decoration: none;
margin: 5px 15px;
}
.desktop-menu {
display: none;
}
.burger-menu {
margin-right: 15px;
cursor: pointer;
}
#dropdown-menu {
position: absolute;
width: 100%;
height: 50%;
top: 33px;
display: flex;
position: fixed;
flex-direction: column;
justify-content: space-around;
align-items: center;
background-color: whitesmoke;
list-style: none;
border: 1px solid;
border-color: grey;
display:none;
}
.hidden-menu {
display: block;
text-transform: uppercase;
font-size: 20px;
color: white;
}
.hidden-menu:hover {
cursor: pointer;
border-bottom: 1px solid;
border-color: grey;
}
/*burger menu*/
div.menulogo1, div.menulogo2, div.menulogo3 {
width: 30px;
height: 3px;
background-color: black;
margin: 6px 0;
transition: 0.4s;
}
/*transition from 3 bar to x bar*/
/*first bar of menu logo*/
.change .menulogo1 {
-webkit-transform: rotate(-45deg) translate(-6px, 3px);
transform: rotate(-45deg) translate(-6px, 3px);
}
/*delete second bar*/
.change .menulogo2 {
opacity: 0;
}
/* third bar rotate*/
.change .menulogo3 {
-webkit-transform: rotate(45deg) translate(-8px, -8px);
transform: rotate(45deg) translate(-8px, -8px)
}
/*body part start here*/
#search-bar {
margin: 70px 20px 10px;
background-color: olive;
}
.main-article {
display: none;
}
.main-galleries {
padding: 20px 15px 15px;
display: flex;
flex-direction: column;
}
.main-galleries h2 {
margin: 10px 0px 10px;
padding: 5px;
}
.gallery-articles {
padding: 10px;
text-align: center;
}
.gallery-articles h2 {
font-size: 25px;
text-transform: uppercase;
padding: 15px 0px 15px;
margin-bottom: 20px;
border-bottom-style: solid;
border-color: grey;
}
.gallery-articles a {
display: block;
margin-top: 40px;
padding: 10px 15px;
cursor: pointer;
border: none;
color: white;
background-color: black;
text-align: center;
transition: 0.3s;
opacity: 0.7;
}
.gallery-articles a:hover {
opacity: 1;
}
.banner-img {
margin: auto;
width: 90%;
}
#slide-galleries {
background-color: gold;
}
footer {
background-color: grey;
}
}
[1]: https://i.stack.imgur.com/yMBf2.jpg
我想我解决了你的问题。 您所要做的就是将z-index:999
(或任何其他高数字)添加到导航栏中。
像这样:
.navbar {
z-index: 999;
}
这允许它位于所有z-index
的顶部,而999
下面有一个z-index
。 您可以在此处了解有关z-index
属性的更多信息。 我希望这能帮上忙!