Shrink the size of the fixed navigation menu

I am experiencing a significant issue with a fixed menu when the browser is resized, as the list items are overlapping and extending beyond their defined section. It's quite frustrating :(. I have been considering two possible solutions: 1: Set a fixed width in pixels for the entire menu instead of a percentage, and scroll the menu horizontally when the browser is resized. 2: Rearrange the list items within the same defined section with borders.

Unfortunately, I have not been successful in resolving this issue. Using overflow to scroll the menu left and right when the browser is resized has not worked. If anyone has a solution for this challenging problem, I would greatly appreciate it :)

Feel free to check out a test page here:

Thank you.

Answer №1

To simplify your styling, you can utilize a script that adjusts your padding and font-size properties:

function customizeMenu(){
                if ($('#containerHeader').exists()) {
                    var resizeObject = {

                        '0-640': '9px,2px,-3px',
                        '640-800': '10px,2px,-5px',
                        '800-1024': '10px,8px,-13px',
                        '1024-1300': '12px,12px,-13px',
                        '1300-2000': '14px,20px,-21px'
                    }

                    var win = $(window);
                    var win_width = win.width();

                    if (win_width > 0 && win_width <= 640) {
                        var value = getValueByKey(resizeObject, '0-640')
                        modifyMenu(value);
                        console.log(win_width + ' : ' + value);
                    }
                    else 
                        if (win_width > 640 && win_width <= 800) {
                            var value = getValueByKey(resizeObject, '640-800')
                            modifyMenu(value);
                            console.log(win_width + ' : ' + value);
                        }
                        else 
                            if (win_width > 800 && win_width <= 1024) {
                                var value = getValueByKey(resizeObject, '800-1024')
                                modifyMenu(value);
                                console.log(win_width + ' : ' + value);
                            }
                            else 
                                if (win_width > 1024 && win_width <= 1300) {
                                    var value = getValueByKey(resizeObject, '1024-1300')
                                    modifyMenu(value);
                                    console.log(win_width + ' : ' + value);
                                }

                                else 
                                    if (win_width > 1300 ) {
                                        var value = getValueByKey(resizeObject, '1300-2000')
                                        modifyMenu(value);
                                        console.log(win_width + ' : ' + value);
                                    }
                }
            }
          function modifyMenu(value){
            var vals = value.split(',')
                $('#containerHeader').find('.roundMenuLi').each(function(index, item){
                    $(item).find('a').css('font-size', vals[0]);
                    $(item).css('padding-right', vals[1]);
                    $(item).css('padding-left', vals[1]);
                    $(item).find('ul').css('margin-left', vals[2]);
              });

            }
          function getValueByKey(obj, myKey){

                $.each(obj, function(key, value){

                    if (key == myKey) {
                        returnValue = value;
                    }
                });
                return returnValue;
            }

-Start by defining your resolutions from 0-600 ... 1300-2000. In the modifyMenu function, assign properties for CSS: 0position-font, 1position-padding left&right, 2position margin left for the second ul level.

Call the script on:

<body onresize="customizeMenu();" onload="customizeMenu();">

Answer №2

Consider adding a minimum width of 1000px (or more... your menu seems to be excessively long in my humble opinion)

to both your permanent #header and to the body section.

By doing this, the overflow-x function will automatically work (without the need to explicitly mention it).

Answer №3

#firstUl > li {
    display:inline-block; 
    vertical-align:top; 
    display:inline; /* display:inline & zoom:1 for ie7 */ 
    zoom:1;
}

Eliminate the height from the ul and ul container, also remove the height from the containerHeader. Instead, utilize padding top and bottom to maintain a gap between the menu and container.

Answer №4

Insert

visibility:hidden;

into the internal CSS of the container element

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

Fuzzy division following a CSS transformation/animation

I have been working on a content slider, using the guidelines from this demonstration However, I have encountered an issue where my content, which consists of a few divs, appears slightly blurry after the CSS transition completes. This problem only seems ...

When executed through nodeJS using the `require('./main.ts')` command, TypeScript Express encountered an issue with exporting and displayed undefined

Describing my issue is proving to be challenging, so I have simplified the code. Let me share the code below: main.ts import express from 'express'; let a = 1 console.log ('a in main.ts', a) export let b = a const app = express() let ...

Passing a pair of variables through an onclick event back to the original page

Is there a way for me to click on a list element and have it display 2 variables on the same page depending on which one I click? Currently, I have two variables defined in the HTML code (although this could be changed as I am hardcoding them into the HTM ...

Issues with Google maps are causing multiple maps to malfunction

After incorporating some jquery code to create multiple maps upon window load, I noticed a peculiar issue with the maps - they all display the same location despite having different latitudes and longitudes set. Upon inspecting the code responsible for cr ...

JavaScript regex problem

As I am handling a specific string: £1,134.00 (£1,360.80 inc VAT) I am currently attempting to isolate the numerical values as follows: ['1,134.00','1,360.80'] My approach involves utilizing this regex pattern in Javascript: /&bs ...

What is the best way to access a specific key value within an array of objects nested within other objects?

In my originalArrayData, I have an array structured as follows: https://i.sstatic.net/soqgt.png Expanding on this: https://i.sstatic.net/H4jXh.png The first item in the array is an object that contains multiple other objects. Here is an example of the ...

Using gmaps4rails: A guide on extracting JSON data from the controller

I have a model named shop and I want to create a simple alert box using JavaScript that shows the name of the shop when a marker on the map is clicked. Here's my code: # controller @json = Shop.all.to_gmaps4rails do |shop, marker| marker.json({ id ...

Exclude striped tr elements within a subtable

I have a main table (Maintable) containing information, with each row having a sub-table for additional details that can be collapsed if needed. I am trying to stripe the rows in the Main table but using `tr:nth-child(even)` is not working as it also affec ...

What is the best method for exporting an HTML page to a PDF file?

After studying the mechanisms of wkhtmltopdf and tcpdf for generating PDF files, I found that wkhtmltopdf allows you to pass a .html file directly to receive a PDF, while tcpdf requires you to code the entire PDF. In my situation, I have a PDF form templa ...

Tips on handling multiple text field validation in material-ui for react?

Currently, I am working on developing a form using Material-UI and React.js where I need to validate two TextField components. My goal is to apply the same error and textHelper props to both TextFields. Below is a snippet of my code for reference. Any sugg ...

Node.js equivalent of Java's byteArray

I have a Node.js REST API with images being sent from a Java application as byte arrays. Here is an image Below is the string representation of the image in byte array form: [B@c75af72 I need to decode this byte array to verify if it is indeed an ima ...

Meteor application: The correct method for fetching a single document from a collection on the client side

Currently in my meteor app, I am saving the unique id of the client within a collection named UserNavigationTracker: { "clientId" : "xxNfxxPGi7tqTbxc4", "currentWizard" : "IntroductionWizard", "currentStep" : "Step-1", "_id" : "ifBJ688upEM ...

Enhancing Visuals with src="imageUrl within Html"

Is there a way to customize the appearance of images that are fetched from an API imageUrl? I would like to create some space between the columns but when the images are displayed on a medium to small screen, they appear too close together with no spacing. ...

Modify the value of a dropdown menu with jQuery if the element's id contains three periods

I'm attempting to utilize JavaScript to modify the value of a select box on a ToysRUs address page. This is part of an extension project that automatically populates an address form. Despite my efforts, I keep encountering null when trying to select t ...

Uh-oh! There seems to be an issue with parsing a cookie

I am encountering an issue while trying to parse a cookie that was created using jQuery in ASP.NET. The error is occurring at line 3 with the message: "Unexpected character encountered while parsing value: %. Path '', line 0, position 0." HttpCo ...

Reposition div when clicked

I have encountered a challenge where I am unable to perform a small task. My goal is to have the position of "div1" change upon clicking on "div2", taking into account that "div2" is nested inside "div1". Additionally, when clicking on "div2" again, "div1" ...

Why is the ajax request in JQuery initiated before the code in beforeSend is fully executed?

I have encountered an issue with my code. I am trying to get a Reload.gif to start playing on my webpage before sending an ajax request to reload the data. However, the GIF only starts playing after the success function is called. Here is the timeline of e ...

Combining jqueryUI autocomplete and datalist for enhanced user input options

My search form in HTML has a single input field where users can enter three different things: area name, trek name, or other keywords. For areas not in a database, I have implemented a datalist field (HTML) connected to the input for autocompleting the a ...

Using Unobtrusive Ajax, learn to integrate data-ajax-confirm with sweetalert

Here is an example of a form using AJAX: <form method="post" data-ajax="true" data-ajax-method="post" data-ajax-complete="completed" data-ajax-confirm="Are you sure you want ...

Tips for creating a script to calculate the population count of a 16-bit integer with either php or javascript

Looking to write a function that calculates the population count of a 16-bit integer in either php or javascript? Population count refers to the number of "turned on" bits, essentially counting the number of ones in the binary representation. For example, ...