在粘性导航栏上的元素

时间:2020-08-06 10:38:44

标签: html css navbar

我正在尝试建立一个网站,并且有一个粘性导航栏(位于标题中)。我添加了一个新部分,并在其中放置了一些文本,但是当我向下滚动时,它超过了导航栏:enter image description here

是否有避免的选择?

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>

谢谢!

1 个答案:

答案 0 :(得分:1)

检查您的navbar是否具有position: fixed以及z-index的值是否高于about-text

.navbar {
    position: fixed;
    z-index: 999;
}

.about-text {
    z-index: 2;
}