Troubleshooting overflow problems when centering a UL menu with an unspecified width

Trying to create a demo where the scrollbars are removed when resizing smaller, but adding overflow: hidden causes issues with sub-menus.

Demo Link

HTML

<nav>
    <ul>
        <li><a href="#">Menu Item</a></li>
        <li><a href="#">Menu Item</a></li>
        <li><a href="#">Menu Item</a></li>
        <li><a href="#">Menu Item</a></li>
    </ul>
</nav>
<p>Struggling to find a way to hide scrollbars without affecting sub-menus.</p>

CSS

nav {
    position: relative;
    zoom: 1;    
    border-top: 1px solid #ccc;
    border-bottom: 3px solid #ccc;    
    float: left;
    width: 100%;
    /*overflow: hidden; */
}
ul {
    clear: left;
    float: left;
    position: relative;
    left: 50%;
    text-align: center;
}
ul li {
    float: left;
    position: relative;
    right: 50%;
}
ul a {
    padding: 5px;
    font-size: 11px;
    display: block;   
}
p {
    text-align: center;
    padding: 30px;
}

Looking for tips on how to center a variable-width UL menu at 100% width?

Answer №1

One option is to try using overflow-x: hidden instead: http://jsfiddle.net/aKUAP/2/

Is there a more effective method for centering a UL menu with an unknown number of items at 100% width?

A better approach would be to use display: inline-block on the ul, and apply text-align: center to the nav: http://jsfiddle.net/aKUAP/3/

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

The issue with ng-bind-html causing the disappearance of paragraph spaces

Is there a way to preserve paragraph breaks when using ng-bind-html to display text on the screen? I am having an issue where all the text appears as one big chunk if there are paragraph breaks in the data pulled from the database. Not sure what is causing ...

Border Effect Resembling Windows Tiles

When you hover your mouse over a tile in Windows, a cool effect happens: Hovering outside the tile, but within the container area: Hovering inside a tile: Hovering outside a tile at its mid point, causing opposite sides to light up: I'm lookin ...

What is the best way to conceal the URL of a link leading to a file?

My website is built with C#, Kendo MVC, Razor and features a Kendo grid where one of the cells contains a hyperlink to a PDF file. The issue I'm facing is that when users click on the link, the URL is visible in the browser and can be altered to acces ...

Enabling draggable behavior for div elements on Mozilla Firefox

I've attempted the code mentioned in this forum but unfortunately, it's not working for me. I am currently using Firefox 15 and it seems to work fine in Chrome. Below is my code : <!DOCTYPE html> <head> <title>A Simple Dragg ...

Navigation menu consist of two horizontal rows

I'm facing a challenge. I have a total of 8 links (one being a button) on a navigation menu that I need to display in two rows on the right side. I'm having difficulty aligning them properly while also justifying them to the right. Essentially, t ...

Is there a way to modify the background color of a button once it has been clicked, specifically using JavaScript?

I am looking to change the background color of a button that I have clicked on in my code. Do I need to use loops and conditions for this task? I attempted to access the first index, but I am unsure how to change the background color of other buttons. l ...

In order to position an inner div in the center and have it expand equally at the top and bottom according to the content size

I am currently working on a layout that involves an inner div with a text div. My goal is to center the inner text div vertically and increase the size of the text div equally from both the top and bottom based on the content size. Below is the approach ...

Parsing HTML files with Perl to extract XML data

Can an XML output be generated from a webpage using web::scraper in Perl? Here is an example of HTML taken from a URL: > <table class="reference"> > <tr> > <th width="23%" align="left">Property</th> > ...

Center two distinct elements using Bootstrap's center-block class

Check out my code snippet below: <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="container"> <div class="row"> <div class="center-block" style="w ...

Unable to connect to a style sheet

I'm in the process of developing a web application and I'm facing an issue with linking a stylesheet to my app. Check out my code below: <html> <head> <title>Bubble</title> </head> <link rel=" ...

Determine the placement of a <div> based on information stored in localStorage

I'm diving into the world of localStorage and trying to figure out how it works. To get a better understanding, I decided to create an HTML page that allows users to drag and drop tiles around the screen. Here's a snippet of the code I came up ...

Triggering a targeted action upon the user's click on any HTML element

Currently, I am in the process of developing navigation buttons that trigger a dropdown sub-menu when clicked by utilizing checkbox inputs. Upon clicking the label, the input is checked, causing the menu to drop down, and when the label is clicked again, t ...

"Encountered a broken image while attempting to send a response with the content-type set as

Within my frontend html, I am looking to include an img element with the source link '/uploads/profilePicture'. In my node/express setup, I need to verify the user's authentication, retrieve their profile picture from the filesystem, and ret ...

Step-by-step guide on downloading an image in HTML with the click of a button

I have a photo gallery on my website created using PHP and HTML. I am looking to add a functionality where users can click on a button to download the image that is currently set as a background of a specific div element in the gallery. The download button ...

In PHP forms, ensure that only completed textboxes are submitted and empty textboxes are discarded

I've created a form that displays all available products from a database along with their prices. Users can input the quantity they want to purchase for each product, and upon submission, the total amount will be calculated. There are 5 products in th ...

What is the best way to achieve this smooth scrolling animation on the page?

While browsing the website , I noticed a unique page scrolling effect that caught my eye. Unsure if they were using default bootstrap code or their own custom code, I was intrigued by how it worked. I attempted to find similar effects online but struggled ...

Is there a feature in JavaScript that allows for the creation of URLs?

I created an index view displaying cards (like playing cards) in a grid using BootStrap. Each card is within its own div element, and I implemented a jQuery click handler for each div to open a details page when clicked. The redirect from the index to the ...

Ways to style specific dates on a datepicker?

Is there a way to customize the appearance of the first and last selected days in my ui datepicker for booking, similar to the design shown in the image linked below? var dateFormat = "DD/MM/YY", from = $("#checkin,. ...

Trouble displaying REACT.jsx in browser

I'm currently learning React and struggling to get it running smoothly. HTML function Person(){ return ( <div class="person"> <h1>Max</h1> <p>Your Age: 28</p> </div> ); } ...

Injecting dynamic data into a function parameter with Angular 1 Interpolation

In my code, I have a feature that alters the text displayed on a button depending on certain conditions. $scope.text = 'Wait'; if(Number($scope.x) == Number($scope.y)) $scope.text = 'Go' else if(Number($scope.x) < Number($scope ...