CSS Navigation Bar Overflowing (taking up 100% of width, overflowing onto next line)

I'm struggling with my aspx master page, where the navigation bar is wrapping around even though I have set the width to 100%. It has worked fine in other projects, so I'm not sure what's causing this issue.

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">© 2016</div>
</div>
<!-- End Footer -->
</div>
<!-- End Wrapper -->

If anyone could assist me with this issue, I would greatly appreciate it. This problem is really frustrating for me. I am trying to create a website with a banner consisting of a heading and subheading, followed by a navbar with specific styling requirements. The content layout includes sections on titans and placeholders, all aligned correctly according to my design.

Answer №1

You're experiencing an issue with the border-right property.

To resolve this, make sure to include box-sizing: border-box;.

.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;
}

Answer №2

Check out this alternative solution. Make this adjustment in your css stylesheet:

.nav-child:first-child {
 /* width: 20%;  Remove this style */
}


.nav-item {
    display: table;
    height: 100%;
    list-style-type: none;
    margin: 0;
    padding: 0;
}
.nav-child {
    border-right: 1px solid #008000;
    display: table-cell;
    font-size: 15px;
    height: 100%;
    overflow: hidden;
    text-align: center;
    vertical-align: middle;
    width: 1%;
}

See it in action: https://jsfiddle.net/4bfg0p18/2/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Allow clicking through the iframe, while still able to interact with its contents

I am facing a challenge of making an iframe click-through, while ensuring that the body of the iframe remains clickable. I have attempted to achieve this using the following code: iframe.style.width = '100%' iframe.style.height = '100%&apos ...

Is there a way for me to generate a tab that shows content when hovered over?

Is it possible to create a tab that displays a vertical list of redirections when the mouse hovers over it, and hides when the mouse is moved away? This seems like a challenging task. Can someone guide me on how to achieve this, especially if it involves ...

Change the appearance of a specific div within a collection of div elements using React

I'm currently working on a visualizer for sorting algorithms where there are colorful bars that will animate when a specific sorting algorithm is triggered by clicking the play button. To achieve this, I created an array of div elements representing ...

Guide to Angular Directives: Assigning Attributes to innerHTML

Looking to add attributes to the inner HTML myTemplate.html <div class="custom-template"></div> HTML <template></template> directive app.directive('template', ['$compile', function($compile) { retur ...

Concealing the footer on a webpage embedded within an iframe

<script> $(document).ready(function(){ $('.mydivclass').hide(); }); </script> Looking to embed Microsoft Forms in my HTML using an iframe. Can the footer of the Microsoft Forms be removed? ...

Menu options

I am currently working on developing a mouseover navigation website. Initially, my design included main buttons for "Our Team", Locations, and Patient Resources. Here is the basic structure I had before attempting to switch to a mouseover approach... &l ...

Tips for eliminating gaps between navigation items (HTML / CSS)

I'm struggling to eliminate the spacing between the li items in my navigation bar. Even after setting margin: 0px for both the item and anchor (link), the gap still persists. How can I get rid of these spaces? /* navigation styles */ nav { backgroun ...

What could be causing my dropdown links to malfunction on the desktop version?

I've been developing a responsive website and encountering an issue. In desktop view, the icon on the far right (known as "dropdown-btn") is supposed to activate a dropdown menu with contact links. However, for some unknown reason, the links are not f ...

Which li in the row is the final target?

In my list of items, there are no special classes assigned to the list items. <ul> <li>item</li> <li>item</li> <li>item</li> <li>item</li> <li>item</li> <li>item</li> ...

Positioning a div relative to another div using the pos:fixed attribute

Is there a way to make a fixed position div relative to its parent div instead of the window using only CSS? I want a sticky block that follows the content while scrolling with the page, and stays in place even when the window is resized. I know this can ...

AHK is unable to fully load all HTML content

I have successfully implemented code to change a frame within the webpage which is working effectively. fr1 :=IE.document.frames[13] fr1.navigate("http blablabla ") However, I am encountering an issue where I need to parse one of the tables on th ...

What is the Best Way to Align a Float Element Perfectly in the Middle of Two Other Floated Elements?

I've encountered a challenge in centering text between two other texts. My Code: <div class="main-container"> <div class="footer"> <span class="left_edge">@left</span> <span class="center">@center< ...

When Google Chrome encounters two variables or functions with the same name, how does it respond?

I am curious what happens when Google Chrome encounters two variables with the same name. In my particular case, this issue arises in the code snippet available at this link, which is a small portion of the entire code. I am facing an issue where placing C ...

Header bar/navigation bar that is constantly changing

Hi there, I'm in the process of creating a dynamic header/navigation bar similar to the one on this website: Here's what I have so far: Jquery: $(document).ready(function() { var lock = $('#header').position().top; $(window).scroll(f ...

Populating datagrid columns with database information post page load

I am currently facing an issue with a web page where loading additional data from an SQL query into a datagrid is significantly slowing down the performance. Despite ensuring that all necessary database indices are in place, the query now takes 3-4 seconds ...

Is there a way to use Selenium with Python to access and open the anchor tag links that are embedded within ul and li tags?

I am trying to figure out how to open the link associated with the anchor tag that has an ID of ViewInvoice. Can someone help me with this? I have attached a snapshot of the HTML page for reference. Snapshot: Highlighted in yellow is the specific item I a ...

Upgrading to .NET 4 Causes DevExpress XtraReports ReportToolbar to Malfunction

After upgrading a website to .NET 4 and implementing XtraReports reports, the toolbar functionality has suddenly ceased. Despite rendering correctly, the page dropdownlist shows a blank instead of the current page, and clicking on any toolbar buttons has ...

The text manipulates the canvas position and changes the location of mouse hover interaction

I am trying to achieve a similar header layout like the one shown on this page. However, when I insert some text within the header section: <div id="large-header" class="large-header"> <h1 style="font-size:150%;">Dummy Text</h1> ...

Forward after asynchronous JavaScript and XML (AJAX)

Currently, I am working on an MVC project where I need to achieve the following: The scenario involves sending an ajax request from a JS script and then redirecting to a page along with a model once the request is processed. I attempted to send a form as ...

Concealed HTML element or generated on-the-fly using JavaScript

What is considered the best practice? I have multiple windows on a page: Auth, Execution Result, and Popups. I can display them in two ways: Create them in pure HTML with CSS, set to display: none, and then fadeIn using jQuery. Create the elements ...