Creating a drop-down layout with multiple columns can improve the organization and aesthetics of your webpage

Looking to achieve a column layout for child <li> elements within nested <ul> elements? Currently, I have the traditional dropdown structure with multiple <ul> items inside <li> tags. My goal is to display these child list items in columns, like having 20 items arranged as four rows of five elements each.

I initially tried wrapping each group of 5 list items in a <span>, but this violates HTML rules since <span> cannot be a direct child of an unordered list. Visually, it works fine, but lacks validation. After researching for solutions, the closest approach I found involves nesting additional <ul> elements within parent <li> tags to simulate column layouts.

However, this method seems excessive and inefficient in terms of HTML markup. If anyone has suggestions on how to efficiently display these list items in columns without violating HTML standards, please share your ideas.

Thank you, Dan.

Answer №1

To achieve the desired layout, you can utilize CSS columns if IE 9 and older browsers are not a priority:

View Example Here

If browsers such as IE 6, 7, 8, and 9 do not support the CSS columns, your menu will still display correctly in a standard vertical format. Alternatively, consider using a polyfill for unsupported browsers.

Below is an example code snippet:

<ul class="parent-list">
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Daddy 1
        <ul class="child-list">
            <li>Child 1</li>
            <li>Child 2</li>
            <li>...</li>
        </ul>
    </li>
    <li>Item 4</li>
    <li>Item 5</li>
    <li>Item 6</li>
</ul>

.parent-list > li {
    float: left;
}

.child-list {
    position: absolute;
    width: 400px;
    -webkit-column-width: 100px;
       -moz-column-width: 100px;
}
.child-list > li {
    width: 100px;
}

POLYFILLS:
CSS3MultiColumn
Columnizer

REFERENCES:
Browser Support Info
W3C Documentation

Answer №2

Experiment with some CSS.

Include a class in the lines:

<li><!--column-->

Try adding something like:

<li class="column"><!--column-->

Then, insert the CSS rule somewhere:

.column{
 float:left;
}

This should solve the issue.

UPDATE: I'm still uncertain if I grasp the problem correctly, but I'll give it another shot :)

<div class='column'>
<ul>
<li></li>
<li></li>
</ul>
</div>

<div class='column'>
<ul>
<li></li>
<li></li>
</ul>
</div>

.column{
 float:left;
}

Is using floated divs a more efficient use of HTML code? (Because to me your nested li's appear ideal).

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

Develop a tree structure that showcases various directory paths

I have a multidimensional array containing various folder paths. My goal is to create a single tree structure from this array, similar to what you see when using the "tree" command in the terminal. Please excuse any mistakes in my English and forgive my li ...

Transforming CSV CSS values with jQuery's CSS method: Step-by-step guide

My goal is to stack multiple background images within a single div container while ensuring their position is relative to the screen height. The problem I'm encountering is my inability to modify CSS values separated by commas. Here is my logical appr ...

Changing the width of an SVG path from 0 to 100% using CSS

I have an SVG design of wires that I want to animate the width from "0 to 100%", but I'm having trouble achieving this effect. It's easy to do with a div element, but not with an SVG image. Below is my code snippet: svg path { animation: f ...

Adding a PHP file into an HTML page using JavaScript include

Recently, I was assigned to collaborate with a third-party vendor who displays movie times on their platform. We were given the opportunity to co-brand our website on their platform by creating a wrapper for our site. This wrapper would allow the movie tim ...

Discovering the exact measurement of "remaining space" in absolute units with flexbox techniques

I am faced with a dilemma that is leaving me uncertain. Within a flexbox layout, specifically column-oriented, there are three children: top, middle, and bottom. The challenge arises in the middle child where I must embed a third-party component that requ ...

Cover the whole page in darkness and emphasize the division element

I attempted to implement a solution I found on stackoverflow without success. The issue is that the blackout feature does not seem to activate - nothing happens. Within my JavaScript code (all enclosed in the $(document).ready(function () tag), it appears ...

What is the proper way to insert a line break within a string in HTML code?

Trying to simplify my code, I've turned to using Nunjucks to pass a group of strings to a function that will then display them. This is what it looks like: {% macro DisplayStrings(strings) %} {% for item in strings %} <div>{{ item.strin ...

Resizing the background while scrolling on a mobile web browser

My website background looks great on desktop, but on mobile (using Chrome) the background starts to resize when I scroll, mainly due to the browser search bar hiding and reappearing upon scroll. Is there a way to prevent my background from resizing? Check ...

Accessing a key from an AJAX JSON response and applying it within a .each() loop in jQuery

I'm struggling with a seemingly simple task that I just can't seem to get right. My goal is to convert multiple text inputs into select fields using AJAX and jQuery. Everything works smoothly, except when trying to make the $.each function dynam ...

Concealing a div element while ensuring that it does not obscure any of its contents

There is a challenge I'm facing that I need help solving. I am using a shop script that only allows me to edit the CSS file. Within this setup, there is a div with a background image and inside there is a normal image: <style type="text/css"> ...

Spin: twist beyond 360 degrees or less than 0 degrees

Attempting to rotate an arrow indicating wind direction using the transform: rotate() property. The data for rotation is retrieved from an API fetch, and conventional measurement of wind direction involves indicating where the wind is coming from. Therefo ...

Arrange and pile up 3 columns using Bootstrap 4

My project currently has a structure using bootstrap columns, as shown in the image below: https://i.sstatic.net/JufaU.png However, I need to change to a lower resolution and rearrange the columns like this: https://i.sstatic.net/IB9sY.png I came acr ...

Guide on showing the D3 Color legend in a horizontal orientation instead of a vertical one

I'm currently in the process of creating a color legend using d3, and I've managed to display it vertically. However, I would like it to be shown horizontally instead. Below is a snippet of the code I've been working on along with a link to ...

Need for Jekyll to Incorporate "excerpt" Liquid Tag in YAML Front Matter

My blog is running on Jekyll 3.0.1, using the Kasper theme with some custom modifications. I've cleared all the posts except one to simplify the issue I'm facing. The site builds correctly when I add an "excerpt" tag with a value in the post&apos ...

In PHP/HTML, if the URL is domain.co.uk/?debug, then the following action will

Apologies for what may seem like a basic question, but I've been searching for a clear answer with no luck! My goal is simple - when someone goes to , I want to show extra details, like the code version or any other notes I include. Once again, sorr ...

Selector matching a descendant element in React styling

I am facing a challenge with using the direct descendant CSS selector within a React inline style element: <style>{` .something>div{ color: blue; } `}</style> While this works fine in development, in production React replaces > ...

How to prevent click events and still enable scrolling within a DIV using CSS/JS

Basically, I am looking to enable scrolling within a DIV while also disabling click events. Any suggestions on how this can be achieved? Appreciate any help! ...

I'm looking to update the background of a webform in asp.net razor - any tips on how to

I understand this is a basic question: How can I change the background color of my Razor web application and also adjust text color within the application? If this has been addressed before, please direct me to that information. Here is the code in quest ...

Invisible Thinglink image revealed upon resizing browser

I am currently repurposing a pre-existing theme that has a drop-down menu showcasing an image. I am attempting to integrate a Thinglink into the content section of this drop-down, but unfortunately, the image does not appear until I adjust the size of the ...

Challenges faced when using Selenium with Telerik RadMenu

For the past two days, I've been struggling to find an effective method for writing integration tests for my ASP.NET website using Selenium. The website features a Telerik RadMenu with a hierarchical structure like this: Root Menu - Menu 1 - Sub M ...