Tips for arranging the items in a dropdown menu side by side

As I work on creating a multi-level navbar using CSS and HTML, I am facing a challenge. I want to structure a drop-down ul-list with multiple columns side by side rather than in a single long column as is traditional. I have tried using the display: flex; property on the ul-list, but so far, I have not been successful.

CSS

ul {
   list-style:none;
   padding: 0;
   margin: 0;
   background: #333;
}

ul li {
   display: block;
   position: relative;
   float: left;
   background: #333;
}

li ul {
   display: none;
}

ul li a {
   display: block;
   padding: 1em;
   text-decoration: none;
   white-space: nowrap;
   color: #fff;
}

.main-navigation li ul li {
   border-top: 0;
}

ul ul ul {
   left: 100%;
   top: 0;
}

ul:before, ul:after {
   display: table;
   content: "";
}

ul:after {
   clear: both;
}

li:hover > ul {
  display: block;
  position: absolute;
}

li:hover li { float: none; }

HTML

<ul class="main-navigation">
   <li>
      <ul>
         <li><a href="#">First Link</a></li>
         <li><a href="#">Dropdown</a>
            <ul>
               <li><a href="#">column1</a></li>
               <li><a href="#">column1</a></li>
               <li><a href="#">column1</a></li>
               <li><a href="#">column2</a></li>
               <li><a href="#">column2</a></li>
               <li><a href="#">column2</a></li>
               <li><a href="#">column3</a></li>
               <li><a href="#">column3</a></li>
               <li><a href="#">column3</a></li>
            </ul>
         </li>
         <li><a href="#">Second Link</a></li>
      </ul>
   </li>
</ul>

Answer №1

Implement the column-count property.

The column-count CSS feature divides the content of an element into the specified number of columns.

MDN

ul.col {
  column-count: 3;
}
<ul class="col">
  <li><a href="#">column1</a></li>
  <li><a href="#">column1</a></li>
  <li><a href="#">column1</a></li>
  <li><a href="#">column2</a></li>
  <li><a href="#">column2</a></li>
  <li><a href="#">column2</a></li>
  <li><a href="#">column3</a></li>
  <li><a href="#">column3</a></li>
  <li><a href="#">column3</a></li>
</ul>

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 reason for needing a page reload in Javascript or JQuery?

I'm curious why Javascript or jQuery require a page reload before applying certain effects. CSS updates in real-time, as demonstrated by the following example: This changes dynamically without needing to refresh the page @media all and (max-width:7 ...

Navigate through previous and next siblings in jQuery until a difference is found

Here's the issue: I have a div with multiple siblings positioned before and after it. For example: <div id="parent"> <div class="invalid"></div><!-- break iteration here !--> <div class="operand"></div> <div cl ...

Search for and swap out a parameter value within an array located in a div using jQuery

A query I have is regarding a div where I am aiming to update the value of a parameter within an array. The PHP code I am using to create the HTML is as follows: <div id="data1<?php echo $data['id']; ?>" data-url="<?php echo 'p ...

The iframe came to a halt as soon as it was no

I am currently developing a live video website that utilizes third-party tools to play the videos. To simplify things, I have embedded all the components required for live video into a single HTML page. Here is how it looks: <iframe data-v-140cfad2= ...

Unable to modify the value of an HTML dropdown list

My latest project is a website located at pg.wcyat.me (Source code), where I utilized github.com/thdoan/pretty-dropdowns for dropdown menus. Using JavaScript, I am able to dynamically change the values of select lists. For example: document.getElementById( ...

Leverage jquery to adjust the height or width of an element depending on which dimension is larger

I'm a beginner in jquery and html and am currently developing a gallery webpage. The functionality involves setting the selected image as the page background and then scrolling vertically based on the mouse pointer's position. This works well for ...

What makes the transparent border colors on <tr> appear too dark?

For instance, take a look at this code: http://jsfiddle.net/WaJy7/ In my attempt to apply a semi-transparent border to every <tr> element, I've encountered an issue where the color of the border appears darker than intended for all rows except ...

A HTML List with Five Columns

Why isn't the CSS code filling up 100% of the screen? I have 5 columns with a width of 20% floating left. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset= ...

The dropdown in MaterializeCSS does not display any data retrieved from VUE

Good evening. I am currently utilizing VUE along with MaterializeCSS. I have been trying to populate a selection menu without success. Although I am receiving the data from the database correctly, the options in the select tag remain blank when using V-F ...

Unlocking the ability to retrieve data generated by the context within getServerSideProps beyond its boundaries (for transitioning from Create React App to Next.js)

I am currently utilizing Create React App for my react application but I am in the process of migrating to Next.js. Accessing URL data such as host, protocol, and query parameters has posed a significant challenge. After some trial and error, I realized t ...

Get the ID from a row that was created dynamically

I have a webpage that pulls information from my database and displays it. Users should be able to click on the "details" link to see more details about a particular record, or click on an input box in the "check" column and submit to update the record stat ...

Having trouble with the Ajax load function not functioning in your HTML code?

The issue has been resolved. Thank you to everyone who helped! Initially, I was attempting to run a file offline instead of on a web server (XAMPP server). Once I uploaded the file to the web server, it started working properly. I had been trying to load ...

In the event of a 404 error, simply direct the user to the pageNotFound before ultimately guiding them back

I'm developing a website with Node JS and I want to implement a feature where if the user attempts to navigate to a non-existent page, they are redirected to a "Page Not Found" message before being automatically taken back to the home page after a few ...

What is the most effective approach to seamlessly conceal and reveal a button with the assistance

I have two buttons, one for play and one for pause. <td> <?php if($service['ue_status'] == "RUNNING"){ $hideMe = 'd-none'; } ?> <a href="#" class="btn btn-warning ...

(Bootstrap) Implementing inline block properties to ensure consistent column display

I am currently working on improving the column layout of a website. However, I am facing an issue where there are large blank spaces if the text lengths or image sizes vary. To test out the theme, I have included some sample products in the image below. h ...

How to modify checkbox and textarea values in a MySQL database with Jquery

In my MySQL database, I have a textarea and three checkboxes. By default, the textarea value is null and the checkbox values are set to zero (0). When I enter text into the textarea, I am able to update the text value in my database. However, I am facing ...

Create a responsive layout of inline-block elements that adjusts to resizing

I am currently focusing on developing the website found at: The progress so far includes successfully creating a list of div.project-item elements that adjust the number of columns based on window resizing due to the use of inline-blocks. My next goal is ...

SQL query for finding the number of shared nodes between two given nodes

How can we determine the common nodes between two specific nodes in SQL, using the following example: Count the occurrences of <li> tags between <h2 id="vgn">VGN A </h2> and <h2 id="vgn">VGN </h2>, as well as the total number ...

The functionality of the Checkbox is experiencing issues when used in conjunction with Bootstrap 5 and Vuejs

Here is a div showcasing an input with its label. However, there seems to be an issue where I am unable to click on the checkboxes. This code snippet serves as an illustration of utilizing Bootstrap 5 checkboxes within VueJs. <ul class="widget-lis ...

Retrieve list of values using Vert.x Json decode function

Is there a way to convert a json string into a List<Foo> object using vert.x? I've found that you can easily convert a string into an object by using Json.decodeValue(data, Foo.class);, but I'm struggling to do the same for lists. Current ...