user3760941 user3760941 - 1 year ago 48
CSS Question

Navbar menu contents overflowing outside of the parent div

I'm trying to get the navbar menu to appear in the 'header-container' menu, but for some reason the navbar links flow outside (before revising browser window). I cannot figure out why but I suspect it has something to do with this line:

div class="collapse navbar-collapse navHeaderCollapse"

Whenever I add a float left to the navHeaderCollapse the links inside. Adding an overflow: none; just hides the overflow but there shouldn't be any overflow in the first place.

Why are the links not staying inside the header-container div?

Appreciate the help, thanks



#header-container{
width: 960px;
height: 50px;
background: #ff0;
margin: 0 auto;
}

<head>
<meta charset="UTF-8">
<!-- STYLESHEETS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>




<header id="header-container">
<div class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<a href="index.html" class="navbar-brand">Brand Name</a>

<!-- MOBILE BUTTON - VIEWABLE ON MOBILE SIZED BROWSERS ONLY -->
<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
<!-- HAMBURGER MENU -->
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>

<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
</ul>
</div>

</div>
</div>
</header>




Answer Source

Just erase the fixed width: 960px; from your #header-container CSS rule

https://codepen.io/anon/pen/LjVjqE

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download