简体   繁体   English

调整大小的导航栏将隐藏网站内容

[英]Resized navbar hides the website content

在此处输入图片说明

I am currently creating a website that is vertically scroll-able and has a navbar on the top as shown in the image. 我当前正在创建一个可垂直滚动浏览的网站,并且该网站的顶部具有导航栏,如图所示。 The navbar gets bigger when the user is not on the very top and this is implemented as: 当用户不在最上方时,导航栏会变大,实现为:

if (window.scrollY == nav.offsetTop) {
    document.querySelector('.nav').classList.add("largerNavbar");
} else {
    document.querySelector('.nav').classList.remove("largerNavbar");
}

In javascript, so, it just adds a new class that has larger height to the navbar. 因此,在javascript中,它仅向导航栏添加了一个具有更高高度的新类。 But the problem is, it hides the content of the 2nd row. 但是问题是,它隐藏了第二行的内容。 The 2nd row's style looks like: 第二行的样式如下:

div#firstRow {
    padding: 10px;
    width: 100%;
    //position: relative;
    margin:0 auto;
    line-height: 1.4em;
    background-color: green;
}

I commented out the position: relative because then the 2nd row will hide the navbar. 我注释掉了位置:相对,因为第二行将隐藏导航栏。

What is the problem here? 这里有什么问题?

EDIT: 编辑:

$font-stack: Helvetica, sans-serif; $ font-stack:Helvetica,无衬线; $primary-color: #333; $原色:#333;

body {

    height: 100%;
    font: 100% $font-stack;
    color: $primary-color;
    margin: 0px;

    .largerNavbar .nav{
        font-size: 20px;
        height: 90px;
    }

    .largerNavbar #firstRow {
        font-size: 20px;
        height: 90px;
    }

    .onSection {

        background-color: gray;

    }

    .nav{

        color: white;

        //vertical center
        display: flex;
        align-items: center;
        font-size: 12px;
        height: 70px;
        overflow: hidden;
        background-color: #333;
        transition:all 1s;
        -webkit-transition:all 1s; 

        .menus {

            position: absolute;
            right: 0px;
            padding: 10px;
        }

        .logo {

            position: absolute;
            left: 0px;
            padding: 10px;          

        }

    }

    .stationary {
        position: fixed;
        top: 0;
        width: 100%;
    }

    .nav a {
        color: white;
        float: left;
        display: block;
        text-align: center;
        padding: 14px;
        text-decoration: none;
    }

    div#firstRow {
        padding: 10px;
        width: 100%;
        //position: relative;
        margin:0 auto;
        line-height: 1.4em;
        background-color: green;
  }

    div#secondRow {
        padding: 10px;
        //position: relative;
        margin:0 auto;
        line-height: 1.4em;
        background-color: blue;
  }

    div#thirdRow {
        padding: 10px;
        //position: relative;
        margin:0 auto;
        line-height: 1.4em;
        background-color: yellow;
    }

      div#lastRow {
        height: 100px;
        background-color: black;
    }

}

    <div class="logo">
        HOME
    </div>

    <div class="menus">
            <span><a href="#about">About</a></span>
            <span><a href="#archive">Archive</a></span>
            <span><a href="#projects">Projects</a></span>
            <span><a href="#contact">Contact</a></span>
    </div>
</div>   

<div id="firstRow">
    <a id="about" class="smooth"></a>

</div> 


<div id="secondRow">
    <a id="history"></a>

</div> 

<div id="thirdRow">
    <a id="contact"></a>

</div> 

<div id="fourthRow">
    <a id="contact"></a>

</div> 

<div id="lastRow">
    <a id="footer"></a>
    footer goes here
</div> 
<script src="bundle.js" type="text/javascript"></script>

I'm guessing that you gave the navbar either absolute or fixed positioning. 我猜您给导航栏提供了absolute定位还是fixed定位。

If that's the case, I would try adding that largerNavbar class to an element that is a parent to both your navbar and your green container there, and then have some CSS selectors that alter both the navbar's height property and the green container's padding-top property at the same time. 如果是这样,我会尝试将largerNavbar类添加到既是您的导航栏又是您的绿色容器的父级的元素中,然后使用一些CSS选择器来更改导航条的height属性和绿色容器的padding-top属性与此同时。

So something like this: 所以像这样:

.largerNavbar .nav {
    ...
    height: 120px; // Use the same height for both
}

.largerNavbar #firstRow {
    ...
    padding-top: 120px // Use the same height for both
}

Add some CSS transitions and it should look great. 添加一些CSS过渡,它应该看起来很棒。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM