Expansive dropdown menu stretching across the entire width, yet the content within restricted to a width of

I have recently made some updates to our website's dropdown menu, expanding the results displayed. However, I would like the dropdown contents to fit within the width of our page.

I have tried adjusting the CSS with limited success:

.menu > ul > li > ul {

Whenever I make changes, the entire dropdown shrinks instead of just the content. My coding skills are basic and I usually work with divs nested inside one another to center them, but that approach seems to mess everything up. It seems like I need to somehow wrap the <li></li> in another container to control the inner content width?

If anyone can assist me, below is the code snippet showing how the dropdown is structured.

          $('.menu > ul > li:has( > ul)').addClass('menu-dropdown-icon');
          $('.menu > ul > li > ul:not(:has(ul))').addClass('normal-sub');
          $(".menu > ul > li").hover(function(e) {
            if ($(window).width() > 943) {
              $(this).children("ul").stop(true, false).fadeToggle(150);
              e.preventDefault();
            }
          });
          $(".menu > ul > li").click(function() {
            if ($(window).width() <= 943) {
              $(this).children("ul").fadeToggle(150);
            }
          });
[CSS styles here]
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div id="headerNavigation" class="hide" style="min-width: 680px;">
<div class="menu-container">
[Menu items structure here]
0.png" alt="Occasional" width="300"></li>
            </ul>
          </li>
        </ul>
      </li>
    </ul>
  </div>
</div></div>

Answer №1

To improve the appearance of the menu, consider incorporating the following CSS properties into .menu > ul > li > ul:

  1. max-width: 1000px; - This restriction will contain the dropdown menu's width to 1000 pixels in case of overflowing content.
  2. right: 0; - By utilizing this attribute, you can elongate the dropdown menu to the opposite side and align it horizontally using auto margins.

          $('.menu > ul > li:has( > ul)').addClass('menu-dropdown-icon');
          $('.menu > ul > li > ul:not(:has(ul))').addClass('normal-sub');
          $(".menu > ul > li").hover(function(e) {
            if ($(window).width() > 943) {
              $(this).children("ul").stop(true, false).fadeToggle(150);
              e.preventDefault();
            }
          });
          $(".menu > ul > li").click(function() {
            if ($(window).width() <= 943) {
              $(this).children("ul").fadeToggle(150);
            }
          });
.mainMenuMulti {
    display: block;
    padding: 8px 20px;
    background-color: #000000;
    color: #C50132 !important;
    font-size: 15px !important;
}
(mainMenuOption {
    display: block;
    padding: 8px 16px;
  }
  .mainMenuSale {
    display: block;
    padding: 8px 20px;
    background-color: #C50132;
    color: #FFF !important;
    font-size: 15px !important;
  }
  .mainMenuClearance {
    display: block;
    padding: 8px 12px;
    background-color: #CCFF00;
  }
  
  .mainMenuOption:hover {
    cursor: pointer;
    background-color: #F0F0F0;
    text-decoration: none;
  }
  
  .mainMenuSale:hover {
    cursor: pointer;
    background-color: #DA0137 !important;
    text-decoration: none;
  }
  .mainMenuMulti:hover {
    cursor: pointer;
    background-color: #333333 !important;
    text-decoration: none;
  }
  .mainMenuClearance:hover {
    cursor: pointer;
    background-color: #C4F400 !important;
    text-decoration: none;
  }
  
  
  .menu {
      width: 100%;
  }
  .menu-container {
    margin: 0 auto;
  }
  .menu img {
      max-width: 100%;
  }
  .menu_heading {
      padding: 5px 10px 10px 0px;
      border-bottom: 2px solid #E5E5E5;
      font-size: 15px;
      color: #00CC00;
      font-weight: bold;
      text-align: left;
      width: 95%;
  }
  .menu_float_1{
      width: 95%;
      float: left;
      padding: 10px 0px;
      text-align: left;
  }
  .menu_float_2{
      width: 49%;
      float: left;
      padding: 10px 0px;
      text-align: left;
  }
  .menu_float_3{
      width: 33%;
      float: left;
      padding: 10px 0px;
      text-align: left;
  }
  .menu-dropdown-icon::before {
    content: "\f489";
    font-family: "Ionicons";
    display: none;
    cursor: pointer;
    float: right;
    padding: 0.7em 1.2em;
    background: #fff;
    color: #333;
  }
  .menu > ul {
    margin: 0 auto;
    list-style: none;
    padding: 0;
  /*  position: relative;*/
    /* IF .menu position=relative -> ul = container width, ELSE ul = 100% width */
    box-sizing: border-box;
        clear: right;
        text-align: center;
  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>"><div id="headerNavigation" class="hide" style="min-width: 680px;">
<div class="menu-container">
  <div class="menu">

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 HTML output generated by JSF component libraries is subpar. Is this level of quality really acceptable?

Back when I worked on web-apps using jsp/jstl and jQuery, I made sure to keep my HTML clean and separate from styles and scripts. JSP would sometimes add unnecessary spaces and blank lines, but that was pretty much it. Now I'm giving jsf a try for de ...

Examining the words within strings and drawing comparisons

I am attempting to analyze words within strings for comparison purposes. This is my objective: var string1 = "Action, Adventure, Comedy"; var string2 = "Action Horror"; if (string1 contains a word from string 2 == true) { alert("found!"); } I have e ...

What is the best way to set breakpoints on Material UI components?

Currently, I am exploring material-ui and I'm curious if there is a way to set all breakpoints at once. The code snippet below seems quite repetitive. Is there a more efficient method to achieve this? <Grid xs={12} sm={12} md={12} lg={12} xl={12} ...

What is the best way to link multiple select tags in an HTML document?

I am working with a data grid that contains student information such as Name, Class, and Score. Each row has a checkbox for selection. The requirement is that when the user selects one or more rows and clicks on the "show information" Button, a new windo ...

Functionality of click events disabled upon loading of ajax content

Can anyone help me figure out how to make the function "live('click',function()" work after an ajax call that returns content with html(data)? I've been searching for 4 hours and haven't made any progress. This part of the code is work ...

Using CSS animations to animate a div while creating a subtle pause between the two

I am working on creating a notification bar that will be displayed and hidden using CSS animation. My challenge is finding the right delay between the two animations. HTML <div id="notification" class="alert" role="alert"></div> JS $(' ...

What is the method for aligning text to the right side within a ListItem?

Currently, I have these elements where the "YoYo" text is aligned to the left by default. However, I am looking to adjust the positioning of some "YoYo" texts so that they can appear on the right side. I attempted to provide a style object with justifyCon ...

Why are the UI components (`Card Number`, `MM/YY`, `CVC`) not being displayed in the React app when using Card

Having an issue where the CardElement Ui component is not visible in the image provided. It should appear above the Order Total: $0 next to the payment method. I've attempted various debugging methods without success. I'm still working on resolv ...

Using RadStyleSheetManager for Optimizing CSS Caching

After implementing the RadStyleSheetManager in my master pages using the given code snippet, I noticed a significant improvement in the performance of my web application. In Internet Explorer 8, the number of dynamically generated WebResource.axd files had ...

Animating elements with CSS keyframes for scaling and translating transformations

I'm having trouble manipulating the size and position of an absolutely positioned div. Even after scaling, the div doesn't end up where I intended it to be in my keyframe animation. I suspect that this issue is caused by the fixed coordinates of ...

"Troubleshooting Problems with Scaling in the jQuery Mouse Wheel Plugin

I am currently utilizing this code in conjunction with the following plugin: mouse wheel $('#painter').on('mousewheel', function(e) { cp.scale(2, 2); var e0 = e.originalEvent, delta = e0.wheelDelta || -e0.de ...

Tips for hiding the overflow scrollbar on Microsoft Chrome when there is no content to scroll

Looking for a solution to hide scroll bars in Microsoft Chrome, but only when there is no content to scroll? The current div and styles always show the horizontal and vertical scroll bars, even when the height exceeds the content. <div style="backgroun ...

Form a bond with the latest SignalR library to initiate communication

After attempting to connect to an asp.net core signalR server using the code below, I encountered some issues. Can you spot where I might have gone wrong? Here is the error message that I received: Error: The "promise" option must be a Promise v ...

Submitting a form using jQuery and processing the response

Can a form be submitted using jQuery without utilizing json, ajax, or other methods for handling the result? For example: <form id="loginform"> //some input fields and a submit button. </form> And then with jQuery: $("#loginform").sub ...

Storing the background color in a JavaScript variable

I've been experimenting with creating a fade in and out effect for a background image on a website. I've also been attempting to capture the background color of a div and store it in a variable. Here's what I have tried: elem = document.ge ...

Tips for extracting data from a JSON file

I'm attempting to retrieve a list of music genres from my json file using PHP and JQuery ajax. Here is the format of my json file [ "12-bar blues", "2 tone", "2-step garage", "4-beat", "50s progression", "a cappella", "accordion", " ...

Enhancing presentation with a multitude of pictures

I am currently in the process of developing a slideshow feature that includes an extensive collection of images for users to navigate through using 'next' and 'previous' buttons. At the moment, each time a user clicks on the navigation ...

Is it time to advance to the next input field when reaching the maxLength?

In my Vue form, I have designed a combined input field for entering a phone number for styling purposes. The issue I am facing is that the user needs to press the tab key to move to the next input field of the phone number. Is there a way to automaticall ...

Troubleshooting: PHP Ajax function fails to post data

I'm having an issue with my Jquery ajax function. It seems that the getinvoices value is not being passed to the PHP file, although I have other Ajax requests in the same file that work perfectly fine. This is the code I am using: Javascript $( "#up ...

Unable to access the done property in an AJAX JSON promise

Trying to dive into the world of JavaScript promises. My goal is to create a button that triggers a function displaying the result of a promise from another function. So far, I've been following tutorials and here's where I'm at: function my ...