Guide on creating a hover-based side menu

I am looking to enhance the sub-menus like PRODUCT 1, PRODUCT 2, etc. by adding side menus that appear when hovering over them. Can anyone assist with implementing this feature in the code below?

Below is the current code snippet:

CSS:

@import url(http://fonts.googleapis.com/css?family=Open+Sans:400, 600, 300);
 @charset"UTF-8";

/* CSS Styles */
 #cssmenu, #cssmenu ul, #cssmenu li, #cssmenu a {
    margin: 0;
    padding: 0;
    border: 0;
    list-style: none;
    font-weight: normal;
    text-decoration: none;
    line-height: 1;
    font-family:'Open Sans', sans-serif;
    font-size: 14px;
    position: relative;
}
#cssmenu a {
    line-height: 1.3;
}
#cssmenu {
    width: 300px;
    margin-left: 90px;
    background: #A3FFFF;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 3px;
    padding: 3px;
    -moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.6);
    -webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.6);
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.6);
}
#cssmenu > ul > li {
    margin: 0 0 3px 0;
}
#cssmenu > ul > li:last-child {
    margin: 0;
}
#cssmenu > ul > li > a {
    // CSS styles for menu items
}
...

JS:

// JavaScript code snippet
(function ($) {
    $(document).ready(function () {
        $('#cssmenu > ul > li > a').click(function () {
            // Click event logic
        });
    });
})(jQuery);

HTML:

<!-- HTML structure -->
<div id='cssmenu'>
    <ul>
        <li class='has-sub'>
            <a href='#'><span>CENTRAL COMPLIANCE</span></a>
            <ul>
                <!-- Sub-menu items -->
            </ul>
        </li>
        ...
    </ul>
</div>

If you can help me customize this code further, I would appreciate it. Thank you.

Answer №1

To effectively utilize the css attribute :hover, begin by setting up a div with a display of none. Then, when hovering over product 1, switch the display to block.

.side-menu {
  display:none;
}
.product1:hover > .side-menu {
  display:block;
}

It's important to remember that this method only works if the menu item you want to hide and show is a child of the item being hovered over. This should not pose a problem for you.

Edit for Clarification: Add a ul in your HTML to hold the side menu. Give the ul a class. Also, give the li for product 1 a class for targeting purposes in CSS.

<li><a href="#" class="product1">Product1</a></li>
  <ul class="side-menu">
    <li>first sub menu item</ul>
  </ul>
</li>

Now, onto the CSS. Use the same class names as mentioned above. When the page loads, the side menu will be hidden due to its display set to none. Hovering over the html element with a class of 'product1' will toggle the display attribute of the side menu from none to block.

Make sure to position the new menu item properly.

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

Is there a way to reduce the excessive bottom margin on Twitter embeds?

Is there a way to adjust the Twitter embed code for tweets so they don't have a large margin at the bottom? Here is an example of the standard Twitter embed code: <blockquote class="twitter-tweet"><p>@<a href="https://twitter.com/gami ...

Why won't my code execute in the script using Python's selenium function driver.execute_script()?

In my python script with the selenium library, I am encountering an issue with the driver.execute_script() function. It seems that only certain parts of the script are being executed while others are not. The following code works properly: driver.execute ...

The header and footer elements must be included along with a main div to house the content on the webpage

I am currently working on building a website using HTML and CSS. I would like to create an index.php file that calls all the different parts of the page. For example, I want to include the header and footer, and also have the ability to replace content wit ...

HTML5 text can display letters and numbers at varying heights

Can anyone explain why the numbers and letters are displaying at different heights? I am utilizing Bootstrap 3. HTML <ul class="list-group"> <li class="list-group-item">HTML5</li> <li class="list-group-item"&g ...

Sorting Arrays with Missing Object Properties

Here is a sample array that I am working with: [ { "id": 1, "name": "Ruan Duarte", "idade": 11, "work": { "id": 2 } }, { "id": 2, "name" ...

Mapping with groups in JavaScript

Is there a way to create a mapping in JavaScript? Currently, I am able to do if (number < 32) { group = 1; else if (number < 72) { group = 2; } else if (number < 100) { group = 3; } else { group = -1; } Instead of this, I am interested ...

Using arrays in Three.js for material instead of MeshFaceMaterial: a guide

I'm starting out with three.js as a beginner. I've run into some issues with MeshFaceMaterial. If anyone has any advice or solutions, I would greatly appreciate it. Thank you in advance! ...

Images that were just added to vite4 and vue3 are not appearing after the build on the production environment

I am facing issues displaying newly uploaded images in my Vue 3 project with Vite 4 on production after building. Despite trying various code snippets from the internet, I have not been successful so far. Specifically, I am attempting to display a user&apo ...

Node.js seems to be having trouble with emitting events and catching them

I'm having trouble troubleshooting my code. // emitter.js var EventEmitter = require('events').EventEmitter; var util = require('util'); function Loadfun(param1, param2, db){ function __error(error, row){ if(error){ ...

Using $npm_package_ notation to retrieve information about the version of a private package

When using Npm, you can easily access package information from the package.json file by using a helpful prefix. For example, you can extract the react version with $npm_package_dependencies_react to find the current version of react listed in the file. Ho ...

There seems to be a problem retrieving the JSON file

My JavaScript file is designed to fetch a JSON file and execute a function if successful. If there's an error, it should display an alert window with the message "error". However, despite checking the syntax, I keep receiving an error alert every time ...

Navigating through the endless scroll behavior in Twitter using CasperJS (PhantomJS)

Having trouble with infinite scrolling on Twitter, as the page is not loading new content even when scrolling to the bottom. To test if any content loads at all, I have used the following code snippet: casper.open('https://twitter.com/<account> ...

Issue: Troubleshooting data serialization process using getStaticProps in Next.js

I attempted to retrieve data from an API, but unfortunately encountered the following error: Server Error Error: Issue with serializing .results returned from getServerSideProps in "/". Reason: JSON serialization does not support undefin ...

Understanding how to use the `e.persist` method in TypeScript can greatly improve

My form validation process using formik includes the code snippet below: {props => { const { values: { email, password }, errors, touched, handleChange, isValid, setFieldTouched, } = props; const change = (name: string, e: ...

What is the average time required for the page to load or respond?

I am curious about the loading and response time of a webpage, specifically how long it takes for a page to load and respond to a given request before timing out. I have noticed that one of my pages is slow to respond and I would like to adjust the durat ...

If the internet connection drops, I would like to show an alert notifying me about the status

Can someone provide guidance on how to display an alert message indicating loss of internet connection using AngularJS in my app? I am currently working with the AngularJS Express framework and APIs. When I encounter a situation where the internet connect ...

Having difficulty altering the div color in real-time using VueJS

I'm currently in the process of building an application with Bootstrap and VueJS. My goal is to create a folder structure similar to Google Drive, where I want to make a div stand out in blue once it's selected. Below is the code snippet: ex ...

Decrease the jQuery version for a particular view exclusively

Imagine a scenario where I am utilizing jQuery version 1.10 in _Layout.cshtml, but need to downgrade to 1.7.2 for certain pages. Is there a way to achieve this without altering the Layout for these specific views? Can this be done at all? :) ...

Angular gives priority to input when clicking an element

Please find the stackblitz link attached below. https://stackblitz.com/edit/angular-dgx3pe My goal is to achieve a functionality where clicking on the label element will focus on the input. This should trigger the input:focus class. I believe this can be ...

What steps should be taken to enlarge a checkbox within a table?

I need help with resizing the checkboxes that are inside a table. When I try using width:###px; height:###px;, it only seems to make them smaller, not bigger. Even when I set the values higher than the default size, the checkboxes stay the same while the d ...