AndrewS AndrewS - 6 months ago 23
HTML Question

CSS Navbar Breaking (width 100%, wraps around onto next line)

I'm working on an aspx master page, and my nav bar is wrapping around even though the width adds up to 100%. What is throwing this off, I've had it work on other projects?

Snippet:



/*General Styling*/

html,
body {
margin: 0;
padding: 0;
height: 100%;
}
#wrapper {
min-height: 100%;
position: relative;
}
.clear:before,
.clear:after {
content: " ";
display: table;
}
/*Header Styling*/
/*Banner Styling*/
#banner {
text-align: center;
border-bottom: 1px solid purple;
}
#banner h1 {
color: blue;
}
#banner h5 {
color: red;
}
/*Nav Styling*/
#nav {
height: 100px;
border-bottom: 1px solid black;
}
.nav-item {
margin: 0;
padding: 0;
display: block;
list-style-type: none;
height: 100%;
}
.nav-child {
overflow: hidden;
font-size: 15px;
border-right: 1px solid green;
float: left;
height: 100%;
text-align: center;
width: 16%;
}
.nav-child:first-child {
width: 20%;
}
/*Content Styling*/
#content {
padding-bottom: 35px;
}
/*Footer Styling*/
#footer {
width: 100%;
border-top: 1px solid orange;
height: 35px;
position: absolute;
bottom: 0;
left: 0;
}

<!-- Start Wrapper -->
<div id="wrapper">
<!-- Start Header -->
<div id="header">
<div id="banner">
<h1>BETTER</h1>
<h5>Battling Elemental Titans Through Exercise Training</h5>
</div>
<!-- Start Navigation Bar -->
<div id="nav" class="clear">
<ul class="nav-item">
<li class="nav-child">
<asp:label ID="exercisePointLabel" runat="server">EP: 500</asp:label>
<br />
<a href="#" runat="server">Add Exercise Points</a>
</li>
<li class="nav-child">
<a href="home.aspx" runat="server">Home</a>
</li>
<li class="nav-child">
<a href="battle.aspx" runat="server">Battle</a>
</li>
<li class="nav-child">
<a href="hallOfLegends.aspx" runat="server">Hall of Legends</a>
</li>
<li class="nav-child">
<a href="settings.aspx" runat="server">Settings</a>
</li>
<li class="nav-child">
<a href="~/account/login.aspx" runat="server">Logout</a>
</li>
</ul>
</div>
<!-- End Navigation Bar -->
</div>
<!-- End Header -->

<!-- Start Content -->
<div id="content">
<!-- Start Titan Sidebar -->
<div id="titans">
<div class="titan-block">titan block</div>
<div class="titan-block"><a href="#" runat="server">+<br /><span class="createTitan">(create new titan)</span></a>
</div>
<div class="titan-block"><a href="#" runat="server">+<br /><span class="createTitan">(create new titan)</span></a>
</div>
<div class="titan-block"><a href="#" runat="server">+<br /><span class="createTitan">(create new titan)</span></a>
</div>
</div>
<!-- End Titan Sidebar -->
<!-- Start Content Placeholder -->
<form id="form1" runat="server">
<div id="body">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

</asp:ContentPlaceHolder>
</div>
</form>
<!-- End Content Placeholder -->
</div>
<!-- End Content -->

<!-- Start Footer -->
<div id="footer">
<div class="footer-text">&copy; 2016</div>
</div>
<!-- End Footer -->
</div>
<!-- End Wrapper -->





If someone could please help that would be amazing. This is driving me crazy. I'm trying to build a website where the banner is, obviously, a banner, with heading and subheading. Followed by a navbar where the first child is an info box slightly wider than the other children, with 5 true navigation elements.

This will then be followed by content, which consists of a left aligned "titan" section, which occupies 100% height down to the footer, with a right aligned "content placeholder" section, also 100% height down to the footer.

Answer

It's the border-right you have.

You should add box-sizing: border-box; to fix this.

.nav-child {
    overflow:hidden;
    font-size:15px;
    border-right:1px solid green;
    float:left;
    height:100%;
    text-align:center;
    width:16%;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
}
Comments