Responsive CSS Dropdown Menu - Divided into Two Columns

After searching for solutions in the support resources and experimenting with various techniques, I am struggling to divide this CSS Dropdown menu into two columns. The nav list is long enough that it extends below the fold.

Although the menu adapts responsively, I specifically need the two-column layout to apply when expanded, not when it shrinks for mobile viewing (which is working fine). Additionally, I'm using a jQuery script in conjunction with my code.

Despite numerous adjustments attempted on my end, I have yet to succeed in splitting the drop-down menu into two side-by-side columns. Any suggestions or guidance on accomplishing this would be greatly appreciated!

Below is the HTML:

<div id='cssmenu' class='align-center'>
<ul>
 <li><a href='index.html'>Home</a></li>
 // Remaining list items omitted for brevity
</ul>
</div>

Provided CSS Styles:

@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700);
// CSS styles omitted for brevity

Here's the jQuery:

(function($){
$(document).ready(function(){

$('#cssmenu').prepend('<div id="menu-button">Menu</div>');
  $('#cssmenu #menu-button').on('click', function(){
    var menu = $(this).next('ul');
    if (menu.hasClass('open')) {
      menu.removeClass('open');
    } else {
      menu.addClass('open');
    }
});

});
})(jQuery);

Answer №1

Check out the HTML code below:

$(function() {
  if ($(window).width() <= 768) {
    $('.sub-menu').hide();
    $('.has-ancho > a').on('click', function() {
      $(this).parent('.has-ancho').toggleClass('open').find('i:eq(0)').toggleClass('fa-rotate-180');
      if (!$(this).parent('.has-ancho').hasClass('open')) {
        $(this).parent('.has-ancho').find('.has-ancho').removeClass('open');
      }
    });
  } else {
    $('.sub-menu').show();
  }
});
.menu-arrow,
.menu-heading {
  display: none;
}
.sub-menu {
  margin: 0px;
  padding: 0px;
  list-style: none;
}
.sub-menu li {
  display: inline-block;
  padding: 5px 10px;
}
.ancho {
  list-style: none;
  margin: 0px;
  padding: 0px;
  text-align: center;
}
@media only screen and (max-width: 768px) {
  .sub-menu li {
    display: block;
    padding: 0px;
  }
  .ancho {
    list-style: none;
    margin: 0;
    padding: 0;
    text-align: left;
  }
  .menu-arrow,
  .menu-heading {
    display: block;
  }
  .ancho a {
    display: block;
    padding: 10px 15px;
    background-color: #e5e5e5;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 3px 0;
    border-radius: 5px;
  }
  .ancho a i {
    float: right;
  }
  .ancho a:hover {
    background-color: #C5C3C3;
  }
  .ancho .has-ancho > ul {
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .ancho .has-ancho.open > .sub-menu {
    display: block !important;
  }
  .ancho .has-ancho.open > a {
    background-color: #B7B7B7;
    color: #FFF;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="container">
  <div class="row">
    <div class="col-sm-6 col-sm-offset-3">
      <ul class="ancho">
        <li class="has-ancho">
          <a href="#" class="menu-heading">menu <i class="fa fa-angle-down menu-arrow"></i></a>
          <ul class="sub-menu">
            <li><a href="#">Home 1</a>
            </li>
            <li><a href="#">Home 2</a>
            </li>
            <li><a href="#">Home 3</a>
            </li>
            <li><a href="#">Home 4</a>
            </li>
            <li><a href="#">Home 5</a>
            </li>
            <li><a href="#">Home 6</a>
            </li>
          </ul>
        </li>
      </ul>
    </div>
  </div>
</div>

Answer №2

Although not the most refined solution, I managed to achieve a two-column layout for screen sizes larger than 480px.

@media only screen and (min-width: 480px) {
    #menu > ul > li > ul > section {
        width: 200%;
    }
    #menu > ul > li > ul > section > div {
        display: inline-block;
        width: 49%;
        white-space: nowrap;
    }
}

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

Submitting a form with multiple actions using Ajax

Is it possible to submit data from multiple forms on the same page to different API tables using AJAX for each form? I have one form that needs to write to one table and another form that needs to write to a different table. How can I achieve this with o ...

Can a callout or indicator be created when a table breaks across columns or pages?

As we develop HTML pages for printing purposes, one specific requirement for tables is to include an indicator like "Continues..." below the table whenever a page or column break occurs. Additionally, in the header of the continuation of the table, we need ...

What could be causing the CSS transition to fail when the menu button is clicked?

After clicking on the menu, a class 'active' is added to both the 'div' and 'section' elements. https://i.stack.imgur.com/jbamR.png The following javascript code accomplishes the above functionality: <script> const ...

How can one remove surrounding paragraph texts using BeautifulSoup in Python?

I'm a beginner in Python, working on a web crawler to extract text from articles online. I'm facing an issue with the get_text(url) function, as it's returning extra unnecessary text along with the main article content. I find this extra te ...

Concealing Vimeo's controls and substituting them with a play/pause toggle button

I'm currently working on implementing the techniques demonstrated in this tutorial (), but unfortunately the code in the fiddle I put together doesn't appear to be functioning correctly. I'm at a loss as to what might be causing this issue. ...

use javascript or jquery to conceal the textbox control

Looking to conceal a textbox control using javascript or jquery. I attempted the following code: document.getElementsByName('Custom_Field_Custom1').style.display="none"; Unfortunately, I received an error in the java console: document.getEle ...

Obtaining Google AAID Using a Mobile Browser (JavaScript)

I've been looking for information online without much success regarding this topic. I am interested in retrieving a user's Google Advertising ID (AAID) through my website when they visit using a mobile browser. I assume it could be done with som ...

Shift the attention from the text box to the AJAX combobox when the enter key is pressed

I need to make it so that when I press the enter key in a textbox, the focus shifts to an ajax combobox. <script type="text/javascript"> $(document).ready(function () { $("#txtGroupSname").keydown(checkForEnter); function checkF ...

How can I make Material UI's grid spacing function properly in React?

I've been utilizing Material UI's Grid for my layout design. While the columns and rows are functioning properly, I've encountered an issue with the spacing attribute not working as expected. To import Grid, I have used the following code: ...

Why is my Ajax utilizing PHP _POST not functioning as expected?

I am facing an issue with the JavaScript code below: <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js'></script> <script> function deletUserInfo(id_user){ console.log(id_user); ...

Is it possible for me to create a CSS class based on a condition using [ngCLASS]?

I am struggling with logic writing in my Angular2 project. On a HTML page, I have two buttons - YES and NO that I want to style with different colors. I have set up a condition in the div tag like this: ngClass="'result'?'yes':' ...

How come the use of a timeout causes the this variable to seemingly lose its reference?

What is the reason why this: myelements.mouseenter(function() { clearTimeout(globaltimeoutvar); globaltimeoutvar = setTimeout(function() { var index = myelements.index(this); console.log(index); // -1 }, 150); }); Returns -1, while this: m ...

IE causing incorrect values to be retrieved from .attr using jQuery

One of the javascript functions I am working on involves using jQuery's .attr method to extract an href value from my pagination link. Here is how the function is called: $(".pager").click(function(){ var start = $(this).attr('href'); ...

Issues arise when using Telerik MVC Controls with the most recent version of JQuery (1.7.1), as client events do not get triggered

After the latest update to JQuery 1.7.1, my Telerik MVC Controls are no longer raising client events. Upon updating to JQuery 1.7.1, I have noticed that all my telerik controls are failing. I'm hoping someone can confirm that this issue is not isola ...

Guide to designing a progress bar using numerical data stored in a database

I am currently working on a project to create a dynamic progress bar based on numeric values stored in a database. The database has two fields, 'NEXT_STEP' and 'MAX_STEPS'. When the value of NEXT_STEP reaches MAX_STEPS + 1, it indicates ...

Searching for a specific text within an element using XPATH in C# with the Selenium framework

My current challenge involves locating specific text within certain elements on an HTML page. <a class="ProductCard-link ProductCard-content" target="_self" tabindex="0" href="/en/product/puma-future-rider-menshoes/314 ...

Creating and launching multiple tabs in node.js (cloud9 IDE): A step-by-step guide

I am currently working on a choice provider. This program will take a (choice) program with a variable number of choices. For example: Let's say we want to make a coffee with two choices - 1. ...

Steps for setting up an info window on a Google map with multiple markers

I'm having trouble getting the infowindow to pop up on the multiple custom markers I added using AJAX on Google Maps. Everything was working fine before I tried implementing the infowindow and adding the listenMarker() function. The icons were in the ...

Tips for enabling background scrolling when Popover is displayed: (React, React Native, Native-Base)

I'm utilizing the Popover component from NativeBase to design my popover: const SettingsButton: React.FC<Props> = () => { return ( <Popover trigger={(triggerProps) => { return ( ...

The loading feature of jQuery UI Autocomplete - .ui-autocomplete-loading is ingenious

When fetching the XML file for the search box, I would like to apply this css. It currently takes around 3 seconds to load the file. In the autocomplete.js file, I found these two functions: _search: function( value ) { this.term = this.element ...