Any solution for preventing the last item in the navigation bar from moving to the next line when the window is resized?

I am attempting to create a horizontal navigation bar with evenly spaced links that span the entire width of the page. I currently have 6 links, each set to approximately 16.67% width, but this is not functioning as expected.

Using 16.5% width works initially, however, when resizing the page, the last item in the navigation bar drops down to the next line. Is there a method to prevent this and ensure that the links remain centered across all window sizes?

Additionally, is there a way to disable users from resizing the window to a size where the links either overlap or are not fully displayed?

Here is the code I have implemented so far:

#navbar {margin:0; padding:0; overflow:hidden; width:100%;}
li      {width:100%}
li a    {padding: 6px 3px; float:left; width:16.5%; text-align:center;}

<ul id='navbar'>
<li><a href='#'> 1 </a></li>
<li><a href='#'> 2 </a></li>
<li><a href='#'> 3 </a></li>
<li><a href='#'> 4 </a></li>
<li><a href='#'> 5 </a></li>
<li><a href='#'> 6 </a></li>
</ul>

Answer №1

When using Safari, the layout appears messy until I eliminate the left/right padding. Because we have already set the width and spacing with CSS, there is no need for additional padding.

Check out the JSFiddle here

#navbar {margin:0; padding:0; overflow:hidden; width:100%;}
li      {width:100%}
li a    {padding: 6px 0; float:left; width:16.5%; text-align:center;}

I am concerned that Internet Explorer may not support the fractional width percentage, so you can attempt this alternative solution.

View the revised version on JSFiddle here

#navbar {margin:0; padding:0; overflow:hidden; width:100%;}
li      {width:100%}
li a    {padding: 6px 0; float:left; width:16%; text-align:center;}

Answer №2

Incorporate a wider width on the #navbar that exceeds the dimensions of all other components.

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

Utilizing :focus-visible pseudo-class on a custom control

A custom control, made of <div tabIndex="0">....</div>, raises the question: how can we ensure that it works with :focus-visible? Sometimes, creating a complex custom control using <div> and <span>, styled to resemble a na ...

Retrieving data from an API after the onClick event is activated

I'm facing a bit of a challenge with an HTML & JavaScript issue, which I believe should be straightforward to resolve. Since frontend development is not really my forte, I am hoping to find some assistance here. Task: A friend who owns a website buil ...

Updating the styling of the highlighted menu options throughout different sections

Currently using ASP.NET MVC "Razor" for my website project, picking up skills along the way. My site consists of 5 or 6 pages internally, with one page linking to an external site. My goal is to create a seamless user experience where all pages feel cohes ...

Unable to achieve desired result when trying to combine styled components props with next adjacent selector

After transitioning from active classes to passing props to styled components, I encountered a minor issue. The prop passing is functioning correctly, but there seems to be an issue with the CSS. Prior to switching to props, this section worked flawlessly ...

What is the best way to adjust a number up or down by one with the push of a button?

Is there a way I can increment and decrement the number 12 by one each time I press the + and - buttons? Additionally, if I have other buttons that need to perform the same function, do I need to assign them the same class name and will they work in the sa ...

Inspecting element value on a website

On a marketplace website, I extracted the attribute (capacity_gold) from a table. Since the values are dynamic and constantly changing, I aim to develop a basic script that will notify me when the attribute value exceeds 100. The current value of the attr ...

Triggering the launch of a fresh screen through the button selection on the current display in HTML

I am currently designing a Twitter website, but I am facing difficulty in solving a particular issue. The problem arises when I try to click on this button: https://i.sstatic.net/g8piA.png My expectation is to see a result similar to this: https://i.sst ...

Contrast two distinct Django models side by side

I've been grappling with a particular issue while working in Django templates for some time now. {% for item in list %} {% if item == {{another variable}} %} //Do Something {% endif %} {% endfor %} The list being iterated over and the second ...

What is the best way to trigger a URL and process all HTML requests on the server?

In the process of developing a test application, I am faced with the task of taking a URL as input and loading the page on the backend (server side) to track all requests made on the page as a typical browser would. This is necessary in order to inspect sp ...

How can I customize the color of Chrome's default date and time picker to a different shade of blue?

Is there a way to customize the color of the blue buttons, text, and date indicator in the native datetime picker for Chrome using CSS? https://i.stack.imgur.com/eZSaE.png ...

Conceal the Angular Material toolbar (top navigation bar) automatically when scrolling downwards

In my Angular application, the main navigation consists of a standard toolbar positioned at the top of the page. My goal is to have this navigation bar smoothly scroll up with the user as they scroll down, and then reappear when they scroll back up. I at ...

Explore the jQuery feature that allows you to hover over text

I'm facing an issue that has got me a bit stuck on how to resolve it. Currently, when hovering over this specific image, the opacity decreases (exposing a background color) and text appears. However, I want this effect to persist even when hovering o ...

Tutorial on integrating jquery ui's '.droppable' feature with the jQuery '.on' method

I have a main div with three inner divs labeled 1, 2, and 3 as shown below: <div id="main"> <div style="height:30px; background-color:yellow;" class="bnr">Banner</div> <div style="height:30px; background-color:yellow;" class=" ...

tips for building angularjs widgets with limited scope

Is there a way to generate widgets from HTML scripts on a webpage? For example: <script type="text/html" id="widget-simple"> <div class="widget-simple"> This is my widget and its name is {{ test }} </div> </script> & ...

CSS Horizontal Timeline Design

https://i.sstatic.net/zBXre.png Looking for an image like this one, with horizontal scrolling navigation buttons to dynamically update the list. I have included CSS and HTML code below. The task should be accomplished using only CSS, but JavaScript can be ...

Directing a webpage to a particular moment within that page

Is it possible to automatically redirect users to a new page at a specific time? I would like visitors to be redirected to a new site starting from 12:00AM on December 31st, without allowing them to access the current site after that time. Is there a way ...

What could be causing my jQuery script to malfunction?

After scouring through numerous Stack Overflow questions and conducting countless Google searches, I am still stumped by the issue at hand. As a beginner in web development, all I want is for this simple page to function properly. Can someone please point ...

Utilize jQuery to generate a dynamic table within a Razor view

I am trying to implement a table in a razor view. <div class="row" style="margin-left:80%"> @if (ViewBag.IsGlobal == 1) { <script> $(document).ready(function () { $("#btnViewLocal").prop("disabled",t ...

I am looking to improve my form submission process by using JavaScript to only submit the form itself, rather than the

I have integrated JS and HTML code. The issue I am facing is that upon submission, the entire page is being submitted instead of just my form. function submit_by_id() { var name = document.getElementById("name").value; var email = document.getElementByI ...

The creation script in create-react-app automatically includes an external import in the CSS file

I am facing an issue with my create-react-app. Everything works perfectly fine when I run it using npm run start. However, after building it with npm run build, some CSS appears to be missing from the app. Upon investigation, I discovered that the file bu ...