Incorporating a translucent backdrop without obscuring surrounding elements

I'm attempting to create a semi-transparent background for a menu while keeping my list and close button unaffected by opacity changes. I attempted to use z-index, but it didn't yield the desired results.

Additionally, the background div seems to interfere with the functionality of the close button icon, preventing me from closing the menu even though the background div is positioned beneath the icon.

Explore My Fiddle:

Visit Fiddle Here

See My HTML code:

<div class="menu">
  <!-- Menu icon -->
  <div class="icon-close">
    <i class="fa fa-remove fa-3x"></i>
  </div>
  <ul>
    <li>Home</li>
    <li>About Me</li>
    <li>Contact Me</li>
    <li>Gallery</li>
  </ul>
  <div id="background"></div>
</div>
<div id="jumbotron">
  <div id="icon-move">
    <div class="menu-icon">
      <i class="fa fa-bars fa-3x"></i>
    </div>
  </div>
</div>

Dive into My CSS code:

#jumbotron {
    width: 100%;
    height: 750px;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-image: url("images/logogreybg.png");
}

.menu-icon {
    color: #fff;
    cursor: pointer;
    font-family: 'Open Sans', sans-serif;
    font-size: 16px;
    padding-bottom: 25px;
    padding-left: 25px;
    padding-top: 25px;
    text-decoration: none;
    text-transform: uppercase;
    z-index:2;
}

.menu-icon i {
    margin-right: 5px;
    color: #3C5F7C;
    z-index:2;
}

.icon-close {
    cursor: pointer;
    padding-left: 25px;
    padding-top: 25px;
    z-index: 1;
}

.icon-close i {
    color: darkred;
    z-index:1;
}

.menu {
    left: -300px;  /* start off behind the scenes */
    height: 750px;
    position: fixed;
    width: 300px;
}

#background {
    height: 750px;
    width: 300px;
    background-color: #000;
    opacity: .25;
    margin-top: -307px;
}

.menu ul {
    list-style-type: none;
    margin: auto;
    margin-top: 40px;
}

.menu li {
    text-align: center;
    color: #fff;
    font-size: 21px;
    line-height: 50px;
}

Peek at My JS code:

$(document).ready(function() {
    $('.menu-icon').click(function() {
        $('.menu').animate({
            left: "0px"
        }, 200);
        $('#jumbotron').animate({
            left: "300px"
        }, 200);
        $('.menu-icon').fadeTo("fast", 0);
    });
    /* Then push them back */
    $('.icon-close').click(function() {
        $('.menu').animate({
            left: "-300px"
        }, 200);
        $('#jumbotron').animate({
            left: "0px"
        }, 200);
    });
});

Answer №1

Instead of using the opacity tag, you can try this:

background-color: rgba(0,0,0,.7);
. I made the necessary edits in your fiddle and it now works perfectly: https://jsfiddle.net/og1fqfsd/2/

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 it possible to execute a function defined within an eval() function using setInterval()?

const evaluation = eval(document.getElementById("codearea").value); setInterval(evaluation, 10); I am seeking a way to access a function that is declared within the eval function, for example: setInterval(evaluation.examplefunc, 10) I attempted ...

Latest versions of Bootstrap are facing issues with the functionality of the Carousel feature

I'm struggling to create a basic carousel, but for some reason, it's not functioning properly. I attempted to use the sample code provided by Bootstrap's documentation, but it doesn't behave as expected (slides won't transition and ...

How can a jQuery fadeTo Effect be timed?

Presently, I am utilizing jQuery's fadeTo function to gradually fade in a div. Nevertheless, I am encountering a slight timing issue. I have an Animated GIF file that I wish to synchronize with the jQuery fadeTo effect. I have tried using window.onlo ...

Unable to view a basic bottle webpage on Raspberry Pi from a PC

After referencing the instructions found at , I successfully tested them on a Raspberry Pi using the following code snippet: from bottle import route, run @route('/hello') def hello(): return "Hello World!" run(host='0.0.0.0', port ...

Guide to sending multiple forms from an HTML page to another PHP page

What is the best way to submit multiple forms on a single HTML page to a PHP page and process all the form elements in PHP upon clicking one button? Any suggestions are appreciated. Thank you in advance. <form id="form1" name="form1"action="abc.php" ...

Is the jQuery Autocomplete Filter malfunctioning?

Currently, I am attempting to implement the jQueryUI autocomplete feature, which will retrieve available tags from a backend source. Below is the code I am using: HTML CODE <div class="span4 pull-right"> Search : <input type="text" id="sear ...

ngClass causing styling issue when applying styles

When I use class names like error and info, the CSS works fine. For example, in this Angular app (latest version) here: https://stackblitz.com/edit/github-i4uqtt-zrz3jb. However, when I try to rename the CSS classes and add more styles, like in the examp ...

What is the best way to inject child nodes into parent nodes without causing the view to shift to the location where the element is being

While I am rendering elements and appending them to a parent div, my screen keeps jumping to the bottom-most element as it loads instead of maintaining the current view. Ideally, it should start at the top of the screen and remain there without any sudden ...

Animate the background of a table cell (td) in React whenever a prop is updated

I have a dynamic table that receives data from props. I would like the background animation of each cell (td) to change every time it receives new props. I've tried creating an animation for the background to indicate when a cell is updated, but it on ...

Generate a JavaScript function on the fly

I am looking for a way to dynamically bind a function to the .click() event of multiple divs in a loop. Once clicked, the function should hide the respective div. Despite my attempts, I have been struggling with losing reference to the div and unsuccessful ...

The disappearing act of a Jquery slide toggle dropdown when the mouse is no longer

Recently, I've been experimenting with creating sliding menus using slidetoggle, slidedown/up effects but I'm encountering some difficulties. Specifically, I am struggling to make the menu dropdown appear when hovering over the main menu item, in ...

Delete all event handlers associated with an element, leaving only one remaining

Is it possible to remove all events from a DOM element except for one using jQuery? Let's say I have a drop down <select> with multiple events attached to it, such as click, double click, and change. How can I specifically target and keep only ...

open and read an HTML file using the _.template function

I've been attempting to utilize underscore.template in order to compile JavaScript templates by loading an HTML file using jQuery.get like this: _.template($.get('my_template.html'), $get(function(data) { return data; })); Unfortunate ...

Learn how to display months on a countdown timer and then customize the format with basic JavaScript for a website

Looking to create a countdown page for the upcoming ICC cricket world cup event that displays the remaining days in two different formats: Format #1: 01 months 10 days 10 hours Format 2: 01 hours 20 minutes 10 seconds (If less than 2 days remain) I curr ...

What is the process for including points to the scoreboard?

I am currently working on a simple JavaScript game as my very first project. The game involves clicking a button to generate random numbers for both the user and computer, and the winner is determined by the larger number. I have set up a scoreboard to kee ...

Creating a PHP-enabled HTML button that spans multiple lines

Currently, I am working on creating a list of buttons with h5 text. The issue I'm facing is that all the buttons have the same width, but when the text exceeds this width, the button expands. I would like the text to span multiple lines without affect ...

Sending PHP emails may encounter issues when there is a URL link enclosed in an anchor tag within the email body

There seems to be an issue with sending emails when including an "a href" tag in the mail body. The email sends successfully when the 'a href' and 'www' tags are removed, but this affects the display of other content as per my requirem ...

Define the hover color options within your personalized Bootstrap 4 design

Currently, I have customized Bootstrap 4.5.3 with some simple modifications. Below is the custom SCSS code I am using: $newcolor1: #00a89c; $newcolor2: #e61b53; $colors: ( "newcolor1": $newcolor1, "newcolor2": $newcolor2 ); $ ...

What is preventing me from receiving the value from the Ajax call?

I have developed an Ajax function that looks like this: function searchPlanAjax(url){ jQuery('#loader').css('display','block'); var plan = jQuery('.rad').val(); var site = url+"fbilling_det ...

Ensure that the video continues playing from where the host left off instead of restarting from the beginning upon reloading

Is there a way to seamlessly stream a video from the host server on my website, so that it picks up exactly where it left off rather than starting from the beginning every time someone accesses the site? I want the video to remain synchronized with the o ...