Expanding unordered list with dual columns upon hovering

Could you possibly assist me with creating a unique navigation effect for my new website? I am aiming to achieve an expandable two-column menu on hover of a parent list item that contains a sub-list.

So far, I have made some progress in implementing this feature. Here is the HTML code:

<header>
    <nav>
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a>
                <ul>
                    <li><a href="#">Sub Link 1</a></li>
                    <li><a href="#">Sub Link 2</a></li>
                    <li><a href="#">Sub Link 3</a></li>
                    <li><a href="#">Sub Link 4</a></li>
                    <li><a href="#">Sub Link 5</a></li>
                    <li><a href="#">Sub Link 6</a></li>
                    <li><a href="#">Sub Link 7</a></li>
                </ul>
            </li>
            <li><a href="#">Top Link</a>
                <ul>
                    <li><a href="#">Sub Link 1</a></li>
                    <li><a href="#">Sub Link 2</a></li>
                    <li><a href="#">Sub Link 3</a></li>
                    <li><a href="#">Sub Link 4</a></li>
                    <li><a href="#">Sub Link 5</a></li>
                    <li><a href="#">Sub Link 6</a></li>
                    <li><a href="#">Sub Link 7</a></li>
                </ul>
            </li>
            <li><a href="#">News</a>
                <ul>
                    <li><a href="#">News Item 1</a></li>
                    <li><a href="#">News Item 2</a></li>
                    <li><a href="#">News Item 3</a></li>
                    <li><a href="#">News Item 4</a></li>
                    <li><a href="#">News Item 5</a></li>
                    <li><a href="#">News Item 6</a></li>
                    <li><a href="#">News Item 7</a></li>
                    <li><a href="#">News Item 8</a></li>
                </ul>
            </li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>
</header>

Here is the CSS code:

...

If you would like to see a demo, click here. However, I am facing an issue where the list items appear to load one by one as the ul grows in size. I would prefer them to be fixed height and fully formed when the ul finishes expanding

To address this, it may require some JavaScript or jQuery, as I aim to avoid making changes to the HTML due to the dynamic nature of the menu on a CMS site. Feel free to ask if clarification is needed.

Answer №1

One effective solution would be to eliminate the usage of css-columns:

column-count:2;
-moz-column-count:2;
-ms-column-count:2;
-o-column-count:2;
-webkit-column-count:2;
column-gap:0;
-moz-column-gap:0;
-ms-column-gap:0;
-o-column-gap:0;
-webkit-column-gap:0

and adjust the selector as follows:

header nav li ul li {
   float: none;
}

to become:

header nav li ul li {
   float: left;
   width: 50%;
}

Check out the fiddle: http://jsfiddle.net/mhu1Lgy2/4/

This may change the order of your links, but you can manage that in your CMS. Additionally, it is advisable to improve the formatting and indentation of your code for better readability.

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 simplest way to increase the size of a child element in order to generate a scrollable area

When working with HTML, it's important to consider how the size of a child div affects the parent div. If the child div is larger than its parent, scrollbars will appear on the parent div if the appropriate style rules are set. However, I'm inte ...

Convert the background image (specified in the CSS with background-image) into a PHP variable

I am looking to create a product gallery featuring 5 products, each with its own background image attribute. I am using a loop to insert the product images and I want each loop to display a different background-image. One approach I have considered is usi ...

Unable to get the DIV to float within its parent div

I'm having an issue with 2 DIV elements (the ones labeled "Module" below) not behaving as expected! When I try to float them so they appear side by side, they end up jumping outside of the parent container and falling below it. I've tried to trou ...

Store the incoming documents from xmpp using the Strophe si-filetransfer feature

I am currently working on adding file transfer functionality to my web application using the strophe.si-filetransfer.js plugin. I have successfully received file details within an iq stanza. My inquiry is, how can I extract the file data from this iq stanz ...

The text sliding feature gradually moves further away from the left side with each iteration

I am in the process of transferring an existing slider from one website to another. Instead of creating a text slider from scratch, I decided to modify the code I found for the new site. However, the slider is not functioning correctly on the new site. Th ...

What is the process for obtaining a list of all registered users?

Is there a way to retrieve a list of all the users registered in my course-booking system? Here's the code in my user.js controller: const User = require("../models/User"); const bcrypt = require("bcrypt"); const auth = require(&q ...

Completing a fetch promise and sending the outcome to a function that is not awaited

I have a function that retrieves data from a Postgresql database and returns it. The expected behavior is to fetch the data using the async function getCat(), process it in const Catalogue, and then return it to a ReactJS component. catalogue.tsx: import ...

Are Stacked DIVs with Variable Height Top DIV Compatible with CSS?

I am currently experimenting with stacking two boxes on my mobile web application view using HTML/CSS. I prefer not to utilize JavaScript or hardcode values in this basic design. Specifics: The top box must have a dynamic height, with contents that ar ...

Tips for restricting additional input when maximum length is reached in an Angular app

In my Angular 6 application, I am working on implementing a directive that prevents users from typing additional characters in an input field. However, I want to allow certain non-data input keys such as tab, delete, and backspace. Currently, I have an if ...

Using react native with a flex of 50% may lead to unexpected errors

Currently in the process of learning react native. Below is the code I am working with: <View> <View style={{flex:0.5,flexDirection="row"}}> <Image source={{uri:"http://image.com/image1.jpg"}} style={{width:100,height:'aut ...

Selenium fails to recognize text

I recently embarked on the journey of learning selenium. I wrote a small snippet of code where I attempted to fetch the price of an item on Amazon. driver = webdriver.Chrome() link = "https://www.amazon.it/AMD-Ryzen-5-3600-Processori/dp/B07STGGQ18 ...

Vue 3 Router view fails to capture child's event

After some testing, I discovered that the router-view component in Vue 3 does not capture events sent from its child components. An example of this scenario is as follows: <router-view @event-test="$emit('new-test-event')" /& ...

Leveraging the power of context to fetch data from a store in a React component within the Next

I'm having trouble with the title in my React project, and I'm new to React and Nextjs. When trying to fetch data from my dummy chat messages, I encountered this error: × TypeError: undefined is not iterable (cannot read property Symbol(Sy ...

Linking two images with an underscore in between

I am facing an issue with the HTML code enclosed within a div: <a href="http://www.mysql.com"> <img src="images/php-power-micro2.png" alt="Image not available" title="PHP" border="0"/> </a> <a href="http://www.php.net"> <img sr ...

Why won't my JavaScript addEventListener activate on form submission?

I have a basic question as a beginner in JavaScript. I am facing some challenges with my first task involving JavaScript. I decided to learn JS by creating a TODO List, but I am stuck right at the beginning. The event listener that should respond when the ...

Executing jQuery AJAX statement to insert data

Struggling with jquery Ajax and need a little guidance! I'm aiming to use jquery ajax and a web service to insert data into the database. Here's a snippet of my html : <title></title> <script src="Scripts/jquery-2.1.1.intellisen ...

Obscured by the overflow

How can I make my navbar stay sticky at the top all the time while scrolling without the content of my cards overlapping it? I am using Bootstrap 5 and have tried setting the position to sticky and overflow to hidden, but the issue persists. Any suggestion ...

How can I execute JavaScript within a for loop in the server-side code?

protected void Button1_Click(object sender, EventArgs e) { for (int i = 0; i < 100; i++) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "myScript", "<script>alert('hello world');</script>"); } } Is th ...

data.failure defined

Currently working on a submission form that utilizes ajax, json, and PHP. The data is being properly handled with the database. However, when I use the script, alert(data.success) returns as undefined. Yet when I alert(data), it shows that what I need is p ...

Ways to extract the directive's value specific to my scenario

I'm currently working on developing a directive for my Angular app, and I need to find a way to pass a value to my controller. Here's what I have so far: controllers.directive('checkBox', function() { return { restrict: &a ...