我正在尝试建立一个网站,并且有一个粘性导航栏(位于标题中)。我添加了一个新部分,并在其中放置了一些文本,但是当我向下滚动时,它超过了导航栏:
是否有避免的选择?
HTML代码:
.about-text
{
background-color: rgb(0, 0 ,0);
/*background-color: rgba(0, 0, 0, 0.5);*/
color: white;
font-weight: bold;
border: 3px solid black;
border-radius: 5px;
margin: auto;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2;
width: 40%;
padding: 20px;
text-align: center;
}
<section id="intro">
<div class="about-text">
<h2>Hey there!</h2>
<h1 style="font-size:50px">I am Tsahi Barshavsky</h1>
<p>Thanks for steping by</p>
<button id="aboutBtn" onclick="window.location.href='#about';">More on me</button>
</div>
</section>
谢谢!
答案 0 :(得分:1)
检查您的navbar
是否具有position: fixed
以及z-index
的值是否高于about-text
.navbar {
position: fixed;
z-index: 999;
}
.about-text {
z-index: 2;
}