Accordion-inspired multi-layer list navigation

I have been searching everywhere but haven't found a solution to this issue. My list menu has the following markup:

<div id="menu">
  <ul>
    <li>Category #1
      <ul>
        <li>Item #1</li>
        <li>Item #2</li>
        <li>Item #3</li>
      </ul>
    </li>
    <li>Category #2
      <ul>
        <li>Item #1</li>
        <li>Item #2</li>
        <li>Item #3</li>
      </ul>
    </li>
    <li>Category #3
      <ul>

        <li>Item #1</li>
        <li>Item #2</li>
        <li>Item #3</li>
      </ul>
    </li>
    <li>Category #4
      <ul>
        <li>Item #1</li>
        <li>Item #2</li>
        <li>Item #3</li>
      </ul>
    </li>
  </ul>
</div>

My goal is to make the menu entirely horizontal and have the items slide out when hovering over each category. Here's a visual example.

It's crucial that the structure remains in a list format, and as far as I can tell, none of the accordions I've come across support this specific feature. Any suggestions?

Answer №1

Is there any question on the lite items with links? If that's the case, you can experiment with a solution like this:

li ul {
    display:none;
}
li, ul, a {
    float:left;
    margin:0;
    padding:0;
    outline:1px solid;
}
li:hover ul {
    display:block;
}

While this example does not incorporate the "slide out" feature, it suggests that incorporating a separate element around the text just before each nested ul may be necessary. (It's important to note that the styling here is purely for illustrative purposes, so feel free to omit the outline if desired ;)

Answer №2

Here, you'll find an implementation of a horizontal accordion feature.

http://www.portalzine.de/Horizontal_Accordion_Plugin_2/index.html

Whether it's horizontal or vertical depends on how the elements are floated.

I discovered this example at the following location:

http://www.catswhocode.com/blog/8-amazing-jquery-accordions

Answer №3

Consider the following:

.navigation ul{margin:0;padding:0;list-style:none;} .navigation li{float:left;top:0;} .navigation li ul{display:none;top:0;} .navigation li:hover ul{display:inline;top:0;}

This code snippet can help you achieve the desired menu layout, but there are drawbacks to be aware of when implementing it. Navigating from one child element to another parent element on the right may result in a jittery experience, and links within multi-level menus may become unusable or unselectable beyond the initial code you provided. The positioning of elements during hover may cause them to lose styling and focus, leading to unexpected behavior.

If your menu structure only requires single-level sub-links, this approach may still be functional. However, for multiple levels of sub-links, many links may become inaccessible due to changes in position or visibility before they can be interacted with.

To mitigate these issues, consider incorporating CSS3 transitions or JavaScript animation to create smoother link interactions. Alternatively, opting for an accordion-style menu that expands and collapses on click rather than hover may provide a more user-friendly experience.

Please note that I have not tested the provided code myself, so some adjustments and testing may be necessary for optimal performance.

In addition, including "top:0" in the hidden state is recommended to prevent abrupt movements during transitions. This property helps maintain the visual consistency of elements as they fade in and out of view.

While this approach may present challenges, you could also leverage the unique collapse effect for design purposes. Experimenting with bold visuals for category backgrounds and using creative imagery for item highlights could potentially turn the navigation into a visually engaging feature.

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

Tips on Getting Your Contact Form Operating Smoothly

Hey everyone, I'm exploring the world of web design and have a question about getting my contact form to work on my current theme. Below is the HTML code I am using: I would greatly appreciate it if someone could help me with coding the PHP file; doe ...

Retrieve multiple data sets

Here's the code I'm currently using, it pulls a random profile picture along with the user's first and last name. It works great, but how can I make it pull more than one at a time? $query = $db->query("SELECT * FROM `content` ORDER BY R ...

How come my image isn't cooperating with text-align and vertical-align?

Hey everyone! I'm a newcomer to this community and a newbie when it comes to HTML. :D I encountered a problem recently and discovered that Stackoverflow is full of amazing developers. That's why I've decided to share my problem here and am ...

Enhanced Visual Studio 2010 with jQuery Mobile Intellisense

Does anyone know how to activate intellisense in Visual Studio for jQuery Mobile? I've been having trouble getting it to work. Any help would be greatly appreciated! ...

Align the text field value with the corresponding tooltip content in Vuetify

<v-col class="d-flex align-center"> <v-tooltip bottom> <template v-slot:activator="{ on }"> <v-text-field v-on="on" :value="info.payeeNo" den ...

Ways to Activate a Modal Using a Hyperlink

One of the features on my Next.js page is a modal that can be triggered by clicking a button: <button type='button' onClick={() => setOpen(true)}> The modal component looks like this: <Modal id='demo' show={isOpen} on ...

Styling Material UI height in select elements (React)

Currently, I am developing a react application that utilizes Material Dashboard. I am encountering an issue with the height of a Select (drop-down list) component. See image here On the right side of my app, there is a standard input field and I would li ...

When there are more than two divs on the page, they tend to overflow beyond the boundaries of

I am managing a platform where users have the ability to share text-based posts, and other users can engage with those posts through comments. An issue I have encountered is that once more than two comments are posted on a parent post, they start to overfl ...

How can I customize the styling of an SVG pseudo element using Font Awesome 5?

I've implemented font awesome 5 pseudo elements to attach an :after tag to my element as shown below: &:after { content: "\f068"; font-weight:400; color:$brandRed; float:right; font-family: "Font Awesome 5 Pro"; } The c ...

Access various results from a jQuery function

Is there a way to efficiently extract the values of petKeys and employeeKey using the jQuery functions provided below? var whenSelectDateFromCalendar = function () { initKeyValues(); petKeys = ? employeeKey = ? }; var initKeyValues = function ...

"Use jquerytools to create a dynamic play/pause button functionality for scrollable content

Greetings! I am currently working on creating a slide using Jquerytools. Here are some helpful links for reference: To view the gallery demonstration, please visit: For information on autoscroll functionality, check out: If you'd like to see my cod ...

working with html data in a bootstrap modal using javascript

Utilizing an id, I pass data to a bootstrap modal and link that id with stored data. $("#fruit").html($(this).data("fruit")); In addition, I am appending data to the bootstrap modal $('#mymodal').find('.modal-body').append('< ...

Can Angular components be used to replace a segment of a string?

Looking to integrate a tag system in Angular similar to Instagram or Twitter. Unsure of the correct approach for this task. Consider a string like: Hello #xyz how are you doing?. I aim to replace #xyz with <tag-component [input]="xyz">&l ...

Maintain text while transitioning to another page

On my webpage (refer to image for details), users need to select options through a series of steps. The process involves clicking on a link in the top box, then entering a search term in the searchbox to display relevant links in div1. Clicking on a link ...

Personalize your Datatable export options with Jquery

I am working with a datatable that contains columns with data in the format 'XXXX unit'. For my export, I need to remove the 'unit' part of the data. What specific rule should I implement for this task? exportOptions: { columns: ...

Trick to enable editing in Bootstrap Select Combobox

Is there a way for users to add their own options to bootstrap-select? Greetings! I have spent some time searching for a straightforward solution that is compatible with Bootstrap 4 styling. Despite exploring various suggestions, as well as unresolved thr ...

Displaying the number zero in TYPO3 Fluid without it being empty or NULL

Within my TYPO3 Fluid template, I am encountering an issue where I need to display a value only if it is not empty. Currently, my approach is as follows: <f:if condition="{myvalue}"> <div class="myclass">{myvalue}</div> </f:if> Th ...

What are the best practices for utilizing CSS position (relative, absolute) combined with percentage dimensions for height and width?

There are numerous questions and answers related to this topic, but I have not come across a case like the one mentioned below. Everyone talks about setting the height and width in percentage by first setting the parent's height in percentage, but it ...

Ways to identify the visible elements on a webpage using JavaScript

I'm working on a nextjs app , I am looking to dynamically update the active button in the navbar based on which section is currently visible on the page. The child elements of the page are structured like this: <div id="section1" > < ...

Is it possible to customize the formatting of the information displayed within a details tag when it is nested under a summary

Is there a way to format the details information so that it aligns underneath the summary tag? Currently, both lines of text are aligned to the left. <details> <summary> Summary 1 </summary> Details 1 </details> ...