Submenu in submenu not registering CSS hover events

Currently, on a website project that I'm developing, there is a submenu nested within another submenu. Interestingly enough, the level-2 submenu happens to be taller than its parent level-1 submenu. To control the visibility of these submenus, I've utilized CSS to dictate that when hovering over the parent list item of the level-1 submenu or the level-1 submenu itself, it should remain visible. This logic is repeated for the level-2 submenu as well. However, upon exiting the bounds of the level-1 submenu, it appears that the pointer events for the level-2 items are no longer being detected.

To witness this behavior firsthand, you can visit the work-in-progress staging site (please excuse the rough appearance as styling is still in progress):

Hovering over categories like "All Categories" and "Native American Artifacts," then attempting to select a submenu item further down the list causes the entire menu to disappear abruptly, suggesting that hover events aren't registering properly once outside the bounds of the level-1 submenu.

  • In Safari, hover events for level-2 submenus do not seem to register at all.
  • In Chrome, hover events for level-2 submenus vanish upon leaving the boundaries of level-1.
  • In Firefox, the submenus behave as expected and remain open while hovered over.

It's worth noting that I'm not using `display:none` to hide submenus before revealing them; rather, I'm employing a combination of `opacity`, `visibility`, and `pointer-events:none` to enable smooth fading transitions. I bring this up because I suspect that maybe my use of `pointer-events` is causing some complications, although I fail to see how that could be the case.

Here's a simplified snippet of the CSS I'm working with:

.sub-menu-level-1 {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

li:hover > .sub-menu-level-1,
li > .sub-menu-level-1:hover {
  opacity: 1;
  visibility: visible;
  pointer-events: initial;
}

Is there something obvious I'm missing here, or is this perhaps a browser-specific issue?

My preference would be to avoid introducing JavaScript into the mix if possible; I personally believe that such functionality shouldn't require additional scripting...

I've scoured through every aspect related to `pointer-events:none`, overflow properties, z-index conflicts, and more...

Below are excerpts of the actual CSS and HTML code:

.menu-wrapper {
  /* Styles omitted for brevity */
}

/* HTML markup removed for clarity */

The expectation is that applying `.item:hover` should trigger corresponding styles during the hover event... right??

Answer №1

It seems like your styling may be getting a bit complex, especially with the use of pointer-events properties. If all items in your menus and submenus are clickable or hoverable, it might be better to keep the pointer-events intact and instead hide the parent container.

Also, nesting your .sub-menu within specific CSS rules within SCSS can make your code less readable. For example:

.menu-wrapper .all-categories .toggle-nav > ul li a .submenu {
    left: calc(~'100% - 20px');
    top: 0;
    border: 1px solid #DDDDDD;
    padding: 20px 30px;
    color: #666666;
}

To keep things simple, try to avoid nesting styles too deeply, ideally not exceeding 5 levels.

If you're having trouble with the :hover state, check if the hover styles for .sub-menu and .see-all-categories are properly defined.

Consider simplifying your code sample and providing a clear snippet to help identify the issue more easily. Sometimes, explaining the problem can lead you to discover the solution on your own.

Answer №2

After completely overhauling the menu CSS, I managed to resolve the issue (even by utilizing opacity: 0 and visibility: hidden instead of display: none). Although not entirely certain about the root cause, I am fairly confident at approximately 86.239% that it was linked to the level-1 submenu's implementation of the columns property and break-inside: avoid on its child menu items. The level-2 submenus being nested within the level-1 menu items likely caused the break-inside attribute to impact those level-2 submenus as well, despite their appearances being visually intact due to absolute positioning. By switching to flexbox instead of css columns, I successfully maintained the same layout with improved functionality.

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

What is the best way to position HTML labels with CSS3 flexbox?

Check out my codepen to see what I need by clicking on this link: https://codepen.io/tbellmer/pen/RdxBdQ I am new to this and although the form works, I require help with the design. I want both the Action: and Comment: labels to be aligned to the right. ...

Utilizing a large logo alongside the NavBar in Bootstrap

Trying to design a sleek navbar that is proportional to the logo size, while also allowing for additional content below it. The jsFiddle link below showcases the current setup. The black line signifies the bottom of the nav bar, which has expanded to matc ...

Looking for some help with tweaking this script - it's so close to working perfectly! The images are supposed to show up while

Hey everyone, I'm struggling with a script issue! I currently have a gallery of images where the opacity is set to 0 in my CSS. I want these images to become visible when scrolling down (on view). In this script, I have specified that they should app ...

JQuery Mobile: Adding fresh, dynamic content - CSS fails to take effect

I've encountered this issue before, but I'm still struggling to resolve it. When adding dynamic content to a page (specifically a list-view), the CSS seems to disappear once the content is added. I've tried using the trigger("create") functi ...

Conceal the Material UI Grid element and allow the following Grid Item to smoothly transition into its place

I need to create a form where certain Textfields must be hidden. However, when I attempt to hide a Grid item within a Grid container using display: none, the next grid item does not move to take its place. Instead, it creates whitespace. Is there a soluti ...

Can a substring within a string be customized by changing its color or converting it into a different HTML tag when it is defined as a string property?

Let's discuss a scenario where we have a React component that takes a string as a prop: interface MyProps { myInput: string; } export function MyComponent({ myInput }: MyProps) { ... return ( <div> {myInput} </div> ...

The bottom section of the webpage fails to follow the CSS height or min-height properties

Taking into account the question I raised earlier: How can a div be made to occupy the remaining vertical space using CSS? I received an answer which I have been experimenting with lately: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "htt ...

How should white space be managed in Bootstrap 4 cards when incorporating responsive column classes - wrap elements inside divs or apply classes directly?

In Bootstrap 4, when applying a responsive column class like "col-sm-8" directly to a "div" with the class "card", whitespace is added between the card border and content. This can be seen in the highlighted yellow area in the image below. https://i.sstat ...

Applying FAB (Material UI) to span across 2 columns in a CSS Grid: A step-by-step guide

Is there a way to make the zero button larger than the other buttons in its row by spanning 2 columns? I would like it to be an oversized oval shape. Appreciate any assistance you can provide. import "./styles.css"; import Button from '@mui/materia ...

position the tooltip within the ample available space of a container in an angular environment

In my editor, users can create a banner and freely drag elements within it. Each element has a tooltip that should appear on hover, positioned on the side of the element with the most space (top, left, bottom, right). The tooltip should never extend outsid ...

Trouble with CSS animations in ThreeJS's CSS3DRenderer

Seeking a way to incorporate plain text (2D or 3D) into a threeJS scene while applying CSS effects, I stumbled upon this resource. It seemed to offer the solution I was looking for. However, when I tried to apply an animate.css class (a well-known CSS anim ...

Animating jQuery Counter with Changing Background Color

I've implemented a Counter that counts from 0 to a specified number, and it seems to be working perfectly. However, I want to add an animation where the background color of a div height animates upwards corresponding to the percentage of the counter. ...

Unique arrangement of hexagons in a honeycomb layout with precise centering

Currently, I am having trouble creating hexagonal blocks with content in a specific layout. My goal is to have four blocks starting with one at the top, followed by a row of two, and finishing with a row of one as shown in the image below. Unfortunately, a ...

Adjusting the size of a bug while hovering over a specific div

Having recently started learning HTML & CSS, I have a question regarding creating a box that scales from 1.0 to 0.8 when hovered over with the mouse. The scaling works perfectly when hovering in the middle (0.0 to 0.8) of the box. However, when hover ...

Transforming data from PHP JSON format into HTML output

Struggling to convert JSON data into HTML format? Having trouble maintaining the correct order of child elements in your structure? Here's a solution: Take a look at this example JSON: { "tag": "html", "children": [ { "ta ...

Problem with logo in MVC4 apps

I'm working on incorporating a logo into my MVC 4 website. When the logo is clicked, it should navigate to the home screen. In order to achieve this, I've added the following code snippet in the _Layout.cshtml file. <a href='<%= Url.A ...

Displaying nested arrays correctly

My latest endeavour involves constructing a data tree in Vue, utilizing components. Let's examine the provided data snippet: "data": [ { "id": 1, "name": "foo", "children": [ { "id": 2, "name": "bar", "children": [] } ...

Using CSS to create a color combination of black with varying opacities

I attempted to achieve a black color by blending together the colors red, yellow, and blue in CSS, but encountered an issue... Is there a way to create black color using opacity? ...

Facing Challenges with Python Selenium while Accessing Specific Form Elements in Salesforce

Recently, I've been using Selenium to automate some data entry tasks on Salesforce. So far, my script successfully loads the webpage, allows me to log in, and clicks an "edit" button. Now, I'm encountering an issue when trying to input data into ...

I am creating accordion-style bootstrap tables using data generated from an ng-repeat loop, all without the use of ui.bootstrap or jquery

My attempt at creating a table with rows filled using ng-repeat is not working as expected. I want a collapsible panel (accordion) to appear on click of each row, but only a single row is rendering with my current code. Here is a link to my code: var ap ...