Displaying wordpress submenu CSS when both the parent and child are active

On my website, I am utilizing a WordPress menu in the sidebar. My goal is to have second level child items appear only when a parent menu item is clicked.

You can view an example here:

I managed to use some CSS code to ensure that the Function Space sub items are visible only when you are on the function space page. However, once you navigate to second level pages like the ballroom, those sub menu items disappear again.

div.custom-sidebar .menu li ul {
     display:none;
}

div.custom-sidebar .menu li.current_page_item > ul,
.menu li.current-menu-item > ul {
     display:block;
}

My question is how do I make the submenu items visible on both the main top level page and all of its subpages (including ballroom, Tropicana showroom, Grand Exhibition Center, Havana Tower function space, South Tower function space).

Please note that I have sub menus on multiple different pages, so I require the CSS code to be generic for the sidebar menu, not specific to the "meetings-menu" class.

Answer №1

To enhance the styling of the current menu item, simply include .current-menu-ancestor in the selectors listed below:

div.custom-sidebar .menu li.current_page_item > ul, 
div.custom-sidebar .menu li.current-menu-ancestor > ul, 
.menu li.current-menu-item > ul, 
.menu li.current-menu-ancestor > ul {display:block;}

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

Steps for modifying the CSS style of a div element following an onclick event:

<html> <head> <style type="text/css"> .step_box { border: 1.0px solid rgb(204, 204, 204); border-radius: 10.0px 10.0px 10.0px 10.0px; } .step_box:hover{ background: rgb(184, 225, 252); } .selected { background-color : #fff000; ...

css Sibling elements restricted within parent container

Encountering an issue with a star rating css example when more than one fieldset is added. The current CSS code seems to be working fine, but it fails when multiple instances of the same elements [fieldset] are present. I've been struggling to find a ...

Utilizing apostrophes in WordPress plug-ins

I am working on a wp wordpress website and encountering an issue with the display of single quotes. I want users to be able to input their own error message in the admin panel. However, if they include single quotes in their input, I want that exact string ...

What is the best way to position a span overlay on a card in the lower right corner

I am looking to add a thumbnail with the duration displayed in the bottom right corner of a video, but I am facing issues moving the span object within the card using Bootstrap 4. Whenever I try to increase the margin-left beyond 50%, the span object crash ...

Issue with Dynamic Theming in Ionic Framework

Currently, I am using Ionic in combination with Angular to create an App. I have introduced dynamic theming by adding two .scss files into my theme folder. In my app.scss file, I define the layout of components without colors, while all color styles are st ...

Arrange four divisions so that they are displayed in pairs on each row when the viewport width is smaller

I have a row of 4 div elements aligned horizontally from left to right. Each div takes up 25% of the screen width. I am looking for a solution to make them wrap when the user resizes the screen instead of overlapping each other. .MenuSett { margin-to ...

Challenges with altering the height of a div through animation

HTML <div class="blok1" ></div> <div class="blok2"></div> <div class="blok3"></div> CSS .blok1 { background-color: green; border-bottom-left-radius:15px; border-bottom-right-radius:15px; h ...

BOOTSTRAP: changing the layout of panels in various sizes for mobile devices

I'm struggling with how to reorganize my panels on mobile devices. Each panel has a different size. Please refer to the attached screenshot for the page layout on large screens (col-lg): https://i.sstatic.net/xcqaT.png EDIT: The layout on large scre ...

Customizing existing Mui classes through the use of makeStyles

Recently, I made a small change in my approach to styling by moving CSS directly into my component files using styled components, emotion, and make styles. This decision was driven by the benefits of easier management and improved development experience. A ...

Navigating through the sticky top navbar in Bootstrap 4 by swiping

I've encountered an issue with a sticky-top navbar that has dropdowns with multiple buttons each. On smaller devices, the navbar gets cropped and I'm unable to access the lower buttons. I'm looking for a solution to add scrolling to this nav ...

Eliminate the mystery overflow in your CSS styling

My website is experiencing overflow on the x axis, even though all vw/width properties are set to 100. I suspect that the .logout element may be causing this issue, but I'm not sure what exactly needs to be modified to resolve it. Any assistance would ...

Tips for utilizing div as a dropdown menu

I have a challenge with the following code and I am looking to make it function like a dropdown one by one For example: ABCD ABCD 1234 ABCD 1234 abcd <ul class="first"> <li class="first-a"><a href="https://someurl">ABCD&l ...

Attempting to toggle the visibility of div elements through user interaction

I'm having an issue with click events on several elements. Each element's click event is supposed to reveal a specific div related to it, but the hidden divs are not appearing when I click on the elements. Any help in figuring out what might be g ...

What are the different ways to customize the indicator color of React Material UI Tabs using hex

Just got my hands on this amazing Material UI component <Tabs textColor="primary" indicatorColor="primary" > <Tab label="All Issues"/> </Tabs> The documentation states that indicatorColor and textColor can only be set to ' ...

Implement a hover effect on a specific class targeting a nested element using JavaScript

Is there a method to apply a class that modifies rules for a child element using Javascript? I have successfully added it with CSS but am struggling to do the same with Javascript. Removing the class in JS is easy by referencing the classname before the ho ...

Concealing spinner controls on HTML Ionic number input

Seeking a foolproof method to conceal spinner buttons on an HTML template for Ionic's number input field. Showcased below is the HTML code that exhibits an input with spinner buttons: <ion-input type='number'></ion-input> The ...

Leveraging the Power of jsPDF in Your Google Apps Scripts

Is it feasible to integrate jsPDF into a Google Apps Script project? I am attempting to create documents using templated HTML, but certain CSS styles like background-color do not translate to PDF when using the getAs() function. Given the limitations of ...

Change your Bootstrap 4 navbar to a two-row layout using Bootstrap 5

Looking to update the navbar from Bootstrap 4 to Bootstrap 5 with two rows I came across this code snippet that works well for me in Bootstrap 4: https://codepen.io/metismiao/pen/bQBoyw But now I've upgraded to Bootstrap 5 and need help converting it ...

What is the most efficient method for designing a sliding list with jQuery?

Recently, I created a sliding list for one of my projects. If you want to see it in action, check it out here. However, I have been thinking lately if there is a more efficient way to achieve the same result. Maybe something already available in jquery-ui ...

Is there a way to eliminate the gap under the image?

https://i.sstatic.net/d73jo.jpg Is there a way to eliminate the gap under the image? ...