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.

https://i.sstatic.net/aR0Qm.jpg

https://i.sstatic.net/e61Ig.jpg

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

What is the best way to retrieve a particular div element from a webpage?

I'm having trouble retrieving a specific div element (specifically with the attribute id="vung_doc") from a website. Instead of getting just that element, I seem to be getting almost every element on the page. Any ideas on what could be causing this i ...

Tips for triggering jquery code when a variable containing a CSS attribute is modified

I have a specific requirement where I need to reset the scrollleft value to 0 on my wrapper whenever a particular CSS property changes. Although I am new to using jQuery and haven't worked with variables much, I believe I need to create a variable to ...

Prevent the propagation of the ng-click event within a jQuery click event

When a Twitter Bootstrap dropdown is nested inside a tr element, and the tr element is clickable through ng-click, clicking anywhere on the page will collapse the dropdown menu. This behavior is defined in a directive using $document.bind('click' ...

Menu within a menu, accessed by hovering

<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <a href="index.html" class="navbar-brand display-4">NintendoWorlds</a> <button class="navbar-toggler" dat ...

Passing data from PHP to jQuery through Ajax by returning an array

Currently, I am attempting to retrieve a PHP returned array using Ajax. This is the Ajax call that I have set up: https://i.stack.imgur.com/FNIvn.png Below is the PHP code that I am working with: https://i.stack.imgur.com/xe8VK.png The query is execut ...

An instructional guide on seamlessly incorporating a TypeScript variable into an HTML element submission method

A problem arises in my Angular 8/Django 3 app as I attempt to incorporate a server-side variable called client_secret into the stripe.confirmCardPayment() method. The error message that keeps popping up is Property 'client_secret' does not exist ...

How can I append the value of an input box to a URL as a parameter upon clicking a button?

I am working on a form with one input field and two buttons, each with different functions. My goal is for one of the buttons to take the value entered in the input field and append it to a specified URL as a parameter when clicked. For example, if the us ...

Use CSS to style an unordered list into a dropdown menu

Would it be feasible to style an unordered list to resemble a dropdown menu using only CSS, without relying on external libraries like jQuery or MooTools? Appreciate your insights. Warm regards, Neil. ...

The validator function is causing an error with the 'lowerCase()' method resulting in an undefined output

Dealing with email validation in a form, I encountered a case-insensitivity issue. Using the angular validation mustMatch to ensure emails match index for index, I needed to address the case sensitivity. This led me to create the matchCaseInsensitivity fun ...

What is the best method for transforming a stream into a file with AngularJS?

Currently, I have a server returning a file stream (StreamingOutput). My goal is to convert this file stream into an actual file using AngularJS, javascript, JQuery, or any other relevant libraries. I am looking to display the file in a <div> or ano ...

Inject CSS values dynamically

I am currently working on dynamically setting the color of a div. To provide some context, let's examine the following: <!doctype html> <head> <link rel="stylesheet" href="style.css"> </head> <body> <div clas ...

Is the ajax success function failing to work properly in JavaScript?

Although I've searched extensively on Stack Overflow, none of the similar questions seem to solve my issue. The problem I'm facing is that the success function is not triggering the alert message and I can't seem to figure out why. <form ...

Obtain the ID of the row that has been selected in jQuery datatable 1.9.4

Apologies if this question has been asked before, but I have searched the web and StackOverflow with no luck in finding a solution. Issue I am trying to retrieve the ID of the selected row from a jQuery data table. My Attempted Code $.each($("#myDataTa ...

Attempting to nest an AJAX request within the success callback of another AJAX request

I am attempting to execute two jQuery ajax calls, with the second call being made from the success callback of the first. I have experimented with different variations of the code, such as adjusting the brackets. Below is my attempted code snippet: $.aja ...

``Are you looking to create multiple canvases in a loop?

I've managed to get this command working exactly as I wanted: http://jsfiddle.net/m1erickson/64BHx/ However, I didn't anticipate how challenging it would be to turn the drawing into reality here: What I attempted to do is illustrated in this li ...

Is there a way to segment a string into words using a dictionary and finding the longest match in JS/Jquery?

Imagine you have a string like this: var str = "thisisinsane"; and a list of words from a dictionary such as: var dic = [ "insane", "i", "is", "sin", "in", "this", "totally" ]; How can we separate the words in str? In this specific case, there a ...

Tips for displaying a Bootstrap 4 table on smaller screens

I have a Bootstrap 4 table filled with JSON data. The table renders perfectly on the UI, but users on smaller devices must scroll to view all the data. Despite there not being much data in the HTML table, users still need to scroll on small devices. I wa ...

Acquiring variables from a JQuery Ajax request while invoking a JavaScript file

I'm currently experimenting with using JQuery Ajax to retrieve a javascript file. I need to pass some parameters to it, but I'm not entirely sure how to do so in Javascript (PHP seems easier for this). Here is my current setup: function getDocum ...

Are the links drifting to the left?

Some of the links on my website seem to be misbehaving and not following the CSS rules, floating to the left unexpectedly. Strangely, it's only the links that are affected; the rest of the text appears fine. For example, you can observe this issue at ...

section featuring a striking visual, user input form, and descriptive content

I want to create a layout with a background image in a div, a signup form on the right side, and a div containing h1 tags on the left side. Here is the HTML code: <html> <title> GoToMy PC </title> <head> <link rel="stylesheet" ...