capturing elements while showcasing others through CSS

I am facing a dilemma with my classes for the menu and content sections of my website. The menu is controlled by .site-header-menu class.

Meanwhile, the content section is managed by the .content class. I want to know how I can target the .content when the .site-header-menu is displayed?

I attempted to use the following CSS code but it didn't work as expected:

.site-header-menu + .content{
  opacity: 0;
}

Do you have any suggestions on achieving this effect using CSS?

I am working with Wordpress, and here is the PHP structure in my header.php file. My objective is to hide the content of the page template when the site-header-menu is open:

<?php if ( has_nav_menu( 'primary' ) || has_nav_menu( 'social' ) ) : ?>
                    <!--<button id="menu-toggle" class="menu-toggle"><?php _e( 'Menu', 'twentysixteen' ); ?></button>-->
                    <button id="menu-toggle" class="menu-toggle" data-title="<?php the_title(); ?>"><?php the_title(); ?></button>


                    <div id="site-header-menu" class="site-header-menu">
                        <?php if ( has_nav_menu( 'primary' ) ) : ?>
                            <nav id="site-navigation" class="main-navigation" role="navigation" aria-label="<?php esc_attr_e( 'Primary Menu', 'twentysixteen' ); ?>" data-title= ''>

                                <?php
                                    wp_nav_menu( array(
                                        'theme_location' => 'primary',
                                        'menu_class'     => 'primary-menu',
                                     ) );
                                ?>

                            </nav><!-- .main-navigation -->
                        <?php endif; ?>

Answer №1

Can you explain how the .site-header-menu is being displayed? Is a class added to show the menu, or is JavaScript directly manipulating its display property? It's unclear how one can determine if the menu is visible.

.site-header-menu + .content{ opacity: 0; }

The rule above will only be effective if the element with class content immediately follows the element with class site-header-menu in the DOM. For instance:

<div class="site-header-menu">
     ... menu stuff ...
</div>

<div class="content">
     ... content stuff ...
</div>

This could possibly be the issue, but it's difficult to confirm without inspecting the output HTML.

If PHP or JS is used to toggle the menu's visibility, you might consider adding or removing an extra class from .content to hide or show it based on whether the menu is displayed.

/* CSS rule to hide the .content element */
.content.hideMe {
     visibility: none;
}

// pseudo-script click event handler (NOT REAL SCRIPT!)
function menuButtonClick() {
     if (menuCurrentlyDisplayed) {
          // menu is already displayed so hide it and show content
          hideMenu;
          removeClass(".content", "hideMe");
     } else {
          // menu is not yet displayed so show it and hide content
          showMenu;
          addClass(".content", "hideMe");
     }
}

If you can share your output HTML or create a fiddle for us to review, that would be beneficial.

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

Unable to use saved images with jQuery Slider

I'm currently facing an issue with adding a jQuery slider to my website. It seems that the slider is not displaying images that are saved on my computer, only images from external websites. Below is the code snippet where I have included an image fil ...

Locate specific text within the content and apply an underline to it

Is there a way to locate specific text on my website and apply an underline to it? Suppose I have some text displayed and I wish to identify all instances of the word hello and underline them. Here is my attempt at the code: $( "body:contains('hell ...

Element's vertical alignment adjustment

Here is the code snippet I am working with: <div style="height:[Variable]px"></div> <!-- or [one or several div and section elements, each with a variable height] --> <div class="Element" style="Position:relative"> <div cl ...

Tips for adding an animated box shadow in CSS without adjusting the shadow's direction

A unique box with a rotating animation was created, however, applying a box-shadow caused the shadow to also rotate along with the box. <!DOCTYPE html> <html> <head> <title>Page Title</title> <style> body{ displa ...

Issue with Bootstrap/Bootswatch Dropdown Tab Not Showing Up

I am encountering an issue while trying to implement a tab with a dropdown navigation, similar to the examples shown on Bootswatch. Interestingly, it seems that this functionality is not working properly even on the demo page provided by Bootswatch. My ma ...

Excessive content in Bootstrap Table

I am currently facing an issue with two tables placed side by side using the Bootstrap grid system. While the tables are dynamic and visually appealing, I encounter a problem when adding lengthy strings dynamically. The overflow of text within the table ca ...

Avoiding duplicate borders in grid layout

I'm working on a crossword puzzle design using css grid The blank cells have no color, while the other cells have a black border. The issue I'm facing is that the borders are overlapping. I've referred to similar questions on Stack Overfl ...

The toggler in Bootstrap 5's Navbar menu is experiencing difficulties opening on mobile browsers

Just arrived here for the first time. Encountering an issue with my Bootstrap 5.1 Navbar menu. Background info: My website is hosted locally via Xampp with php pages for forms and cookies. Everything functions perfectly on desktop. Checked responsiveness o ...

The persistent bar that refuses to abide by z-index rules in the Google Chrome browser

While working on a website, I decided to add a navigation bar in ribbon style. To ensure it sticks to the top of the viewport when the user scrolls, I used the jQuery Sticky Plugin. Everything was running smoothly in Firefox, but unfortunately Chrome star ...

Error Message: The function "menu" is not a valid function

I've encountered an issue with a function not being called properly. The error message states "TypeError: menu is not a function." I attempted to troubleshoot by moving the function before the HTML that calls it, but unfortunately, this did not resolv ...

Troubleshooting: How can I ensure my custom scrollbar updates when jQuery niceselect expands?

I am currently utilizing the jquery plugins mCustomScrollbar and niceselect. However, I have encountered an issue when expanding the niceselect dropdown by clicking on it - the mCustomScrollbar does not update accordingly. I suspect this is due to the abso ...

Incorporating style to select buttons within a Vue.js application: A step-by-step guide

Take a look at the code below: <template> <DxPopup v-bind="$attrs" v-on="$listeners" :hide-on-outside-click="true" :drag-enabled="true" :wrapper-attr="popupAttributes" pos ...

How to Integrate a DIV Table with Ajax.BeginForm in MVC4

My goal is to integrate a div table with Ajax.BeginForm: This combination will generate the following structure: <div class="Table"> <div class="Title"> <p>This is a Table</p> </div> <div class="Heading"> & ...

in Vue.js, extract the style of an element and apply it to a different element

Currently, I am using VUE.js 2 in my project. Here is my website's DOM structure: <aside :style="{height : height()}" class="col-sm-4 col-md-3 col-lg-3">...</aside> <main class="col-sm-8 col-md-9 col-lg-9" ref="userPanelMainContents" ...

Enabling overflow-y with the value of auto allows the child element to be

I'm having an issue with a parent element and a child element in my CSS code. The parent has the following properties: position: relative; overflow-y: unset; And the child has these properties: position: relative; left: -70px; Everything looks good ...

Bootstrap 3 offset doesn't respond to dimensions

Even though I have set an offset for a medium-sized screen, the offset still appears in large screens. Here is a snippet of my HTML code. How can I resolve this issue? <div class="col-lg-6 col-sm-12"> <div class="row"> <div class="co ...

Searching for a way to smoothly scroll horizontally from right to left using the mouse wheel?

I am looking to display 3 out of my collection of over 6 articles, with the ability for the user to scroll from right to left when using the mouse wheel. Additionally, I want to hide the scrollbar for a cleaner look. Can anyone assist me with this? I hav ...

Achieving Content Alignment Using CSS

I successfully implemented a design on my HTML page that divides it into three sections vertically, with each section having a different background color - white, gray, and black. The backgrounds stretch the full width of the page regardless of screen reso ...

Variety of image widths displayed in bxslider

I am currently facing a challenge while using the bxslider with images of varying sizes that I want to have the same height but different widths. My goal is to create a carousel similar to the ones shown in the examples on . While these examples work well, ...

Troubleshooting the compatibility issue between Gravityforms and Jquery File Upload

I want to integrate the JQuery File Upload plugin with Gravity Forms in Wordpress. I've set up a form with a file upload input where Gravity Forms has assigned the field id as input_1_33. This id is being used for the file upload jQuery plugin. jQuer ...