Navigate effortlessly with our vertical multi-level menu - simply hover over an option to reveal the next level of

This particular image demonstrates a vertical menu that is expanded. I am looking to display only the parent tag initially and upon hovering, show the next level and so forth.

function display_children($parent, $level, $categoryModel) {

    $result = $categoryModel->get_category($parent);
    echo "<ul>";
    foreach ($result as $row) :
        if ($row['Count'] > 0) {
            echo "<li><a href='" . base_url() . "/index.php/advertisement/category/" . $row['category_id'] . "'>" . $row['category_name'] . "</a>";
            display_children($row['category_id'], $level + 1, $categoryModel);
            echo "</li>";
        } elseif ($row['Count'] == 0) {
            echo "<li><a href='" . base_url() . "/index.php/advertisement/category/" . $row['category_id'] . "'>" . $row['category_name'] . "</a></li>";
        } 
            else;
    endforeach;
    echo "</ul>";
}

The above code is what I have written, and now I require CSS for it. Since it involves recursive logic, I am feeling unsure about how to proceed. Most of the CSS resources I found were for horizontal menu listing, but I specifically need a vertical menu layout.

Answer №1

Creating a unique CSS cascade interaction with nested lists. By strategically hiding and revealing elements, we can achieve an interesting visual effect.

ul{
/*If bullets are outside, hover effect will flicker.*/
list-style-position:inside;
}

ul ul{
display:none;
}

li:hover>ul{
display:block;
}
<ul>
  <li>
    A
    <ul>
      <li>B</li>
      <li>C</li>
    </ul>
  </li>
  <li>
  D
    <ul>
      <li>
      E
        <ul>
          <li>F</li>
          <li>
          G
            <ul>
              <li>H</li>
              <li>I</li>
            </ul>
          </li>
        </ul>
      </li>
      <li>
      J
        <ul>
          <li>K</li>
          <li>L</li>
        </ul>
      </li>
    </ul>
  </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

Assigning event to the body element

Is there a way to bind an event to the entire page, specifically the html or body tag? I am trying to achieve the following: document.addEventListener('mousemove', function() { alert('a'); }); I want an alert to be triggered whenever ...

Increase transparency of scrollbar background

Is it possible to adjust the opacity of a scrollbar track? I attempted to use opacity:0.5, but it didn't have any effect. I am using material UI styled, although I don't believe that is causing the issue. const Root = styled('div')(({ ...

Continuously I am being informed that the value is null

Check out this code snippet: var Ribbon = /** @class */ (function () { function Ribbon(svg) { // Code here... } Ribbon.prototype.init = function() { // Initialization code here... }; Ribbon.prototype.updateR ...

Can you explain the inner workings of the delegate() and live() methods?

How do the delegate() and live() methods in jQuery possess the capability to function for both existing and potential elements on the webpage? ...

How to extract the value of an HTML text field by executing an SQL query in PHP

Sign In Page: Here is where users can enter their login credentials. Method used is PHP POST. <html> <head> <title> LOG IN </title> <style> body { text-align: center; } </style> </head> <body> <form ac ...

What is the best way to center a fixed position background image within a container that is slightly shifted from the top of the viewport?

How can I center a background-image vertically, which has a fixed background-attachment and is positioned 100px from the top? The background-size property is set to cover for horizontal centering but the vertical alignment is off. Below is the HTML code: ...

The alignment of the label button within the form-group is being set to the top

While using Bootstrap 4, I encountered an issue with aligning the save button in a form group because there was no label at the same level. Despite trying to follow an example from here, I still had to hard code margin-top to prevent the button from bein ...

Creating an element that remains fixed once it reaches a distance of 50px from the top of the screen

Hey there! I'm working with an html div element that currently scrolls along with the page, but I was wondering how I can make it become fixed once it reaches a distance of 50px from the top of the screen. Any ideas on how to achieve this? Just to pro ...

What could be causing my view to not load the jQuery code from _Layout.cshtml, yet it works when I include it directly in the view file?

Why is the jQuery inherited from Layout.cshtml not loading in my view? When I use a local link to jQuery in the view, it works fine. Otherwise, it doesn't. _Layout.cshtml: <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...

CSS/jQuery animation alignment problem

Exploring an animation using CSS transitions and jQuery has been my recent project. The concept involves presenting the user with clickable divs to load a new page. When a div is clicked, it expands to cover the entire screen and transition to the next pag ...

Creating dynamic visual effects for text on image with animation

I have created an animation where an image transitions from black and white to colored upon hover, accompanied by overlay text. However, when hovering over the text, the image reverts back to black and white. How can I ensure that the image stays in color ...

Ways to access a JavaScript object beyond the function scope

Using the code below, I am able to retrieve JSON data when an element is clicked. This data is then used to create a table, fill the cells with images, and append the table to a specific div. function LoadImagesByCategory() { $.getJSON("/Service/GetJs ...

Guide to incorporating Jquery-Comment into Angular versions 2 and beyond

I've incorporated the Jquery-Comment plugin into my Angular 2 project by adding the necessary script and css files to my Index.html page. However, when initializing the Comment TextBox id within a script tag, I encountered an error in the console. ...

Issue with scrollable multilevel dropdown menu

Dealing with an extensive menu list, I aimed to restrict them using a scroll. In the demo on CodePen, everything works fine without the scroll. However, upon adding overflow-y:scroll; height:200px;, it leads to an overflow-x issue and hides all the dropd ...

Issue with Slick Grid not updating after Ajax request

I need to update the data on a slick grid when a checkbox is clicked, using an ajax call to retrieve new data. However, I am facing issues where the slick grid does not refresh and the checkbox loses its state upon page load. Jsp: <c:if test="${info ...

Click a button to switch the visibility of a section in an

Is there a way to create a toggle feature in Angular.JS that will open and close a div when clicked on the same div again? Currently, it opens the div when clicked but I want it to also close the div when clicked again. <a ng-href ng-click="openAccordi ...

Iterate over div elements using jQuery

I am experimenting with creating a jQuery slider using divs: <div id="block-1"> <div id="bannerleft"> <div class="wsite-header-1"></div> </div> <div id="bannerright"> < ...

Oops! Smarty encountered a fatal error that wasn't caught

An error occurred while processing the template file "C:\xampp\htdocs\eventos\libs\templates\teste.tpl" on line 9. The error message states: Fatal error: Uncaught exception 'SmartyCompilerException' with message &apo ...

Deactivate weekends when checkbox is marked and reactivate them when unchecked

Hello everyone! I've been experimenting with the code below in an attempt to enable/disable weekends on a datepicker, but it's not working as expected. What I'm aiming for is to disable weekends when a checkbox is checked and enable them whe ...

"The Ajax function for replacing a div upon change event is not functioning properly

I am having an issue with my select box using the onchange event, <select class="form-control" onchange="getval(this.value,'<?php echo $prd->pr_id;?>','ajax<?php echo $key?>','<?php echo $key ?>')"&g ...