Bootstrap - navbar-fixed-top covers content

后端 未结 6 1465
醉酒成梦
醉酒成梦 2021-02-12 14:36

I have a question about navbar-fixed-top. Well, I have a simple problem with it. My fixed navbar covers content, for example in \"About us\" page, it covers row with \"About us\

6条回答
  •  [愿得一人]
    2021-02-12 15:32

    It's possible setting a variable for the paddingTop of the body to the height of the navbar could also work and is subsequently a bit more responsive than a fixed 60/65px value.

    let padding = $("nav").height() + "px";
    

    A practical example is the Bootstrap .navbar-toogler button and adding a click event to it and setTimeout function which allows the height to change then apply the new value as paddingTop to the body.

    jQuery:

    $(".navbar-toggler").click(function(){
                setTimeout(function(){
                    let padding = $("nav").height() + "px";
                    $("body").css("paddingTop", padding)
                }, 500)
            })
    

    vanillaJS:

    document.querySelector(".navbar-toggler").onclick = function(){
                setTimeout(function(){
                    let padding = document.querySelector("nav").offsetHeight + "px";
                    document.body.style.paddingTop=padding;
                }, 500)
            };
    

提交回复
热议问题