top nav bar blocking top content of the page

前端 未结 19 1337
孤城傲影
孤城傲影 2020-11-28 00:48

I have this Twitter Bootstrap code

  
相关标签:
19条回答
  • 2020-11-28 01:33
    <div class='navbar' data-spy="affix" data-offset-top="0">
    

    If your navbar is on the top of the page originally, set the value to 0. Otherwise, set the value for data-offset-topto the value of the content above your navbar.

    Meanwhile, you need to modify the css as such:

    .affix{
      width:100%;
      top:0;
      z-index: 10;
    }
    
    0 讨论(0)
  • 2020-11-28 01:35

    I am using jQuery to solve this problem. This is the snippet for BS 3.0.0:

    $(window).resize(function () { 
        $('body').css('padding-top', parseInt($('#main-navbar').css("height"))+10);
    });
    
    $(window).load(function () { 
        $('body').css('padding-top', parseInt($('#main-navbar').css("height"))+10);        
    });
    
    0 讨论(0)
  • 2020-11-28 01:35

    In my project derived from the MVC 5 tutorial I found that changing the body padding had no effect. The following worked for me:

    @media screen and (min-width:768px) and (max-width:991px) {
        body {
            margin-top:100px;
        }
    }
    @media screen and (min-width:992px) and (max-width:1199px) {
        body {
            margin-top:50px;
        }
    }
    

    It resolves the cases where the navbar folds into 2 or 3 lines. This can be inserted into bootstrap.css anywhere after the lines body { margin: 0; }

    0 讨论(0)
  • 2020-11-28 01:38

    For bootstrap 3, the class navbar-static-top instead of navbar-fixed-top prevents this issue, unless you need the navbar to always be visible.

    0 讨论(0)
  • 2020-11-28 01:39

    Add to your CSS:

    body { 
        padding-top: 65px; 
    }
    

    From the Bootstrap docs:

    The fixed navbar will overlay your other content, unless you add padding to the top of the body.

    0 讨论(0)
  • 2020-11-28 01:39

    a much more handy solution for your reference, it works perfect in all of my projects:

    change your first 'div' from

    <div class='navbar navbar-fixed-top'>
    

    to

    <div class="navbar navbar-default navbar-static-top">
    
    0 讨论(0)
提交回复
热议问题