Finding it challenging to maintain the alignment of the Drop Down Menu in the center while adjusting the

When I resize my browser or view the page on mobile, the drop-down menu becomes misaligned and extends off the screen. I suspect that adjusting the padding levels might resolve the issue, but previous attempts have only caused more problems.

I would appreciate any guidance or assistance with this matter.

https://i.sstatic.net/UkY8L.png https://i.sstatic.net/mTulO.png

[

$('.drop-down').click(function() {
        $(this).hide();
    });
    $('.nav-main li').click(function() {
        $('.drop-down').hide();
    });
    //drop down slide down
    $('.nav-main li ul').hide().removeClass('.drop-down');
    $('.nav-main li').hover(
        function openDrop() {
          $('ul', this).stop().slideDown(900);
        }, 
        function closeDrop() {
          $('ul', this).stop().slideUp(1000);
        });
    
.nav-main {
      position: absolute;
      top: 0;
      height: 65px;
      width: 100%;
      text-align: center;
      }
      .nav-main ul {
      position: relative;
      margin: 0 auto;
      padding: 0;
      list-style: none;
      font-size: 22px;
      line-height: 100%;
      font-family: 'Futura W01 Bold', sans-serif;
      text-align: center;
      text-transform: uppercase;
      display: inline-block;
      width: 100%;
      }
      /* More CSS styles... */
    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <nav class="nav-main" role="navigation">
    <ul>
    <li class="nav-top"><a href="#welcome">Welcome</a></li>
    <li class="nav-top"><a href="#about">About</a>
    <ul class="drop-down">
    <li class="nav-drop"><a href="#about">Services</a></li>
    <li class="nav-drop"><a href="#client">Clients</a></li>
    <li class="nav-drop"><a href="#press">Press</a></li>
    <li class="nav-drop"><a href="#leadership">Leadership</a></li>
    <li class="nav-drop"><a href="#twitter">Follow Us</a></li>
    </ul>
    </li>
    <li class="nav-top"><a href="#contact">Contact</a></li>
    </ul>
    <span class="nav-arrow"></span>
    </nav>

]3

Answer №1

To target a specific browser width and adjust the font-size of the menu for smaller screens, you can use a @media breakpoint.

@media only screen and (max-width: 767px) {
  .nav-main ul {
    font-size: 18px;
  }
}

For a practical demonstration, check out this JSFiddle example (resize the window to see the effects).

Feel free to customize the font-size value and threshold width according to your preferences. You may also want to consider adjusting other styles such as paddings.

Answer №2

One way to address this issue is by incorporating media queries into your code. Media queries allow you to customize CSS based on the specific screen size of a device. If you want to learn more about how media queries work, check out this informative guide.

Answer №3

Although the responses provided are accurate regarding the use of a @media breakpoint, I would recommend utilizing 'rem' units for measurements instead of "px". Employing relative units offers numerous benefits

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

Tips for incorporating 'and' in the 'on' clause of 'join' in knex.js

I need assistance implementing the following SQL code in knex.js: select c.id,c.parent_id,c.comment,u.username,c.postid from comments as c join post_details as p on (p.id = c.postid and c.postid=15)join users as u on (u.id = c.userid); I attempt ...

Combining the inline JavaScript linting tool ESLint with the popular Airbnb configuration and Facebook

In my current project, I am utilizing ESLint and looking to incorporate Facebook flow. However, I am encountering warnings from ESLint regarding flow type annotations. Within the project root directory, I have both .flowconfig and .eslintrc files present. ...

Is it possible for images underneath to receive focus when hovering over them?

I'm struggling with a layout of thumbnails on my page. We'll refer to them as A, B, C, etc. They are currently displayed like this: A, B, C, D, E, F, G, H, I, J, K, L, M, N... and so on. When you hover over one thumbnail, it enlarges by 2.5 t ...

How can we verify that console.log has been called with a specific subset of expected values using Jest?

I am currently experimenting with a function that adds logging and timing functionality to any function passed to it. However, I am facing a challenge when trying to test the timing aspect of it. Here are my functions: //utils.js export const util_sum = ( ...

I am struggling to find the correct way to fetch images dynamically from Cloudinary and display them as backgrounds. How should I go about implementing this feature successfully

I have been trying to figure out why I am unable to retrieve the image from cloudinary. My goal is to use the image as a background when posting, but it seems like I am not fetching the image correctly. function Post({post}){ return( <div ...

Disable the use of componentWillUnmount in case of an incomplete form

I have implemented a form using redux-form and I am trying to set up a scenario where if any of the form's inputs have content and the user tries to navigate away from the page, a prompt should appear. My goal is to prevent the page from being unmoun ...

ways to utilize inline styling in react using javascript

When repurposing an array of React components, I am looking to modify the inline styles generated with them. How can I access and log the inline styles of a React component? UPDATE: see the code snippet below: const pieces = this.props.pieces.map((decl, ...

Troubleshooting: Height setting issue with Kendo UI Grid during editing using Jquery

Issue: My Kendo UI JQuery Grid is fully functional except for a bug that occurs when adding a new record. When I add and save a new record, the grid's footer "floats" halfway up the grid and the scrollbar disappears, making it look distorted. Furth ...

convert a string to JSON format using Node.js Express

Currently, I am viewing some string data in a browser that has been processed using python-node js express. The data looks something like this: In order to manipulate the data more effectively, I would like to convert it into JSON format that follows this ...

How to solve the issue of synchronizing data fetching from a json-server and displaying it in the UI with React?

While working with json-server to retrieve data and display it in the UI, I often face a recurring issue that leaves me puzzled. The process of fetching data is asynchronous, which means that setting the state after fetching the data takes some time. As a ...

Using ng-repeat in Angular causes the style of a div to become hidden

Utilizing angular ng-repeat to generate multiple divs, the original template html code is as follows: <div class="span5 noMarginLeft"> <div class="dark"> <h1>Timeline</h1> <div class="timeline"> <div c ...

Displaying a dynamic splash screen during the resource-loading process on an Android application

I would like to implement an animated image (currently using a set of PNGs) as a splash screen while my resources are loading. I have successfully displayed the splash screen using this method. However, the issue I am facing is that the splash screen appe ...

choose to display on mobile devices as a dropdown menu rather than a modal window

On mobile devices, my select elements are currently displayed as modals with options. However, I need to change this appearance to resemble the dropdown list view observed on desktop devices. Your assistance is greatly appreciated. ...

Jquery error caused by index variable in form validation issue

While attempting to validate 8 radio buttons, I encountered a peculiar issue related to indexing. The process involved looping through the 8 radio buttons to check if they had been selected. If all 8 buttons remained unchecked, an alert would be triggered ...

Angular mistakenly uses the incorrect router-outlet

Encountering an issue with Angular routing. The main app has its own routing module, and there is a sub module with its own routing module and router-outlet. However, the routes defined in the submodule are being displayed using the root router outlet inst ...

JavaScript and modifying the attributes of the nth child

I'm working on a navigation bar that changes the "background-image" of menu items using the nth-of-type CSS selector. Now, I need to figure out how to dynamically change the picture of the "background-image" when hovering over a specific menu item usi ...

Ways to incorporate horizontal scrolling in mat autocomplete

I have an Angular app with auto complete functionality. I am trying to add horizontal scroll to the mat-option by applying CSS styles, but it's not working as expected. .cdk-overlay-pane { overflow-x: auto; } I also tried following the instruc ...

Steps to combine multiple arrays into a unified array:1. Begin by allocating a

To form a league table, I have multiple individual arrays filled with data. In order to sort them by points, I want to merge these arrays into a single array called "teams". However, I am unsure if there is a function available to achieve this specific f ...

Managing fresh data entries in meteorology

In my current setup, I have a "requests" collection and I have successfully set up publications on the server side and subscriptions on the client side. My question is, how can I effectively handle new records in MongoDB? Specifically, I would like to re ...

Error: The object referenced does not have a function called 'findById' within its methods when trying to export

I have come across a number of similar questions on this platform, but most of them seem to be related to HTML. My issue involves encountering an error while submitting a login form in Java. Here is a Very Simple Save Function: var model = require(' ...