简体   繁体   中英

Twitter Bootstrap 3 - Navbar Fixed Top - Overlaps content when multiple lines

First, this is not the body padding-top issue for the fixed top navigation.

body { padding-top: 40px; }

I've got a navbar that, for better or for worse, has a lot of data/information in it. The issue I'm having is that when the navbar breaks into multiple lines (which is perfectly fine) it overlaps the content (bad).

Here is an examples of what I'm seeing/experiencing. http://jsfiddle.net/jsuggs/ZaMs3/7/

Does anyone have either a clever javascript solution to change the body padding or a way to force a collapse when the navbar breaks into multiple lines?

Update

Here is what I ended up using. I had to add in some additional padding and combined the load and resize events.

$(window).on('load resize', function() {
    $('body').css({"padding-top": $(".navbar").height() + 30 + "px"});
});
$(window).on('resize load', function() {
    $('body').css({"padding-top": $(".navbar").height() + "px"});
});

http://jsbin.com/iJaJAzIM/2/edit

One possible solution is to use media queries to check for different widths. Something like

@media screen and (max-width: 1414px) and (min-width: 768px) {
    body {
        padding-top: 80px;
    }
}

@media screen and (max-width: 902px) and (min-width: 768px)  {
    body {
        padding-top: 120px;
    }
}

worked for me on Chrome on your Fiddle.

The downside to this solution is, that it needs a lot of tweaking and changing if you modifiy your navigation elements and it might be hard to get it right on all browsers...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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