Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

overflowing navbar in bootstrap

I'm experimenting with Bootstrap 3.2. I'm trying to create a fixed at top navigation bar but I'm running into two problems:

  1. The navigation bar overlaps the content below it.
  2. The navigation bar seems to be going far off the screen to the right. This makes my button in the navigation bar not visible unless the window width is dragged to a smaller size.

For the first problem, I've followed the Bootstrap example tip by adding a class to my css file, including this file below the Bootstrap css file in the html document, and then referring to the class.

.navbar-height{
    body{padding-top: 200px;}
}

<body class="navbar-height">

Though, this seems to do nothing (as you can see I specified the number really high hoping to see a dramatic change, which did not occur).

Here's my the navigation bar:

<header id="header-navigation">
        <div id="nav-bar-container">
            <nav id="nav-bar" class="navbar navbar-default navbar-fixed-top" role="navigation">
                <div id="nav-item-container" class="container-fluid">
                    <div id="drop-down" class="navbar-header">
                        <button type="button" class="btn btn-default navbar-btn navbar-toggle collapsed" data-toggle="collapse" data-target="#user-dropdown">
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <div id="home-button" class="navbar-left">
                            <a class="navbar-brand" href="#"><img alt="Brand" src=""></img></a>
                        </div>
                    </div>
                    <div id="user-dropdown" class="navbar-collapse collapse">
                        <ul class="dropdown-menu" id="dropdown-items" role="menu">
                            <li>
                                <div class="list-group-item">
                                    <div class="row-picture">
                                        <img class="circle" src="" alt="icon"></img>
                                    </div>
                                    <div class="row-content">
                                        <h4 class="list-group-item-heading">Placeholder</h4>
                                        <p class="list-group-item-text">Placeholder</p>
                                    </div>
                                    <div class="list-group-seperator"></div>
                                </div>
                            </li>
                            <li><a href="#"><span class="glyphicon glyphicon-log-out"></span></a></li>
                        </ul> 
                    </div>
                </div>
            </nav>
        </div>
</header>

As a quick break down of the above code, I have a <header> tag which will hold the navigation bar. Within this <header>, I have a containing <div> (id="nav-bar-container") which only purpose is to act as a container for the navigation bar (maybe I'll add something else to the header and want to keep the bar seperate). Then, I have the actual <nav> which has the appropriate classes (or so I think): "navbar navbar-default navbar-fixed-top". The next <div> (id="nav-item-container") holds the components of the navigation bar. The following <div> (id="drop-down") contains the button (which seems to disappear at full-screen) and a link with a "brand", which always seems to be visible. The last major <div> contains the "drop down" content for when the button is pressed.

My Question: why is my navigation bar overlapping the content below it and over extending to the right hiding the button?

like image 259
chRyNaN Avatar asked Nov 29 '25 07:11

chRyNaN


1 Answers

Ok, first thing, you don't need the <header> tag, so feel free to remove that.

Second, from the Docs on navbar-fixed-top, you need to have padding:

body { padding-top: 70px; }

Notice you applied it to the heading style; that won't work. Apply it to the body and it works fine.

As far as the 2nd issue, I don't actually see any horizontal scrolling when I removed the <header> tag, so I think that may have been causing an issue.

Checkout this Bootply example:

Bootply Example

To see what I mean. It's your code with the tag removed. Hope that helps!

like image 162
Tim Lewis Avatar answered Dec 01 '25 20:12

Tim Lewis