Unable to render a child div completely opaque using the opacity attribute

I am currently working on a popup feature that, when displayed, will blur the background of the page to a grey color. The .cover element is responsible for this overlay effect. Unfortunately, I am facing issues overriding its default opacity:0.6; property with the use of !important. My objective is to make the inner <div> opaque while keeping the parent element transparent.

Here is the HTML structure:

    <div id="cover">
        <div id="popup">
            <img src="EFTI_POPOVER2.png" alt="endurance films institute" id="pop-img">
            <button id="pop-but" onclick="location.href='http://endurancefilmsti.com/sales/'">
                <span id="#but-span">
                    <strong>YES!</strong>
                </span>SHOW ME THE FUTURE OF ENDURANCE SPORTS TRAINING</button>
            <a id="back" href="#">No Thanks, Continue Shopping</a>
            <a href="#" class="cancel">&times;</a>
        </div>
    </div>

For the CSS styling:

#cover{ 
    position:fixed; 
    top:0; 
    left:0; 
    background:rgba(0,0,0,0.6); 
    z-index:5; 
    width:100%; 
    height:100%; 
    display:none; 
    opacity:0.6;
} 
#pop-img {
    opacity: 1 !important;
}

Answer №1

Before you open your .cover, make sure it is closed first. Changing the opacity to 0.6 will affect all child nodes as well. To achieve the desired outcome, you should increase the z-index of #popup.

<div id="cover"></div>
<div id="popup">
    <img src="EFTI_POPOVER2.png" alt="endurance films institute" id="pop-img">
    <button id="pop-but" onclick="location.href='http://endurancefilmsti.com/sales/'">
        <span id="#but-span">
            <strong>YES!</strong>
        </span>SHOW ME THE FUTURE OF ENDURANCE SPORTS TRAINING</button>
    <a id="back" href="#">No Thanks, Continue Shopping</a>
    <a href="#" class="cancel">&times;</a>
</div>

Answer №2

According to the rules, opacity affects not only the element itself but also all its child elements.

Here's an example in pseudo code for elements with less than full opacity:

  1. Create a buffer for a bitmap image.
  2. Copy the content of the element into the bitmap buffer.
  3. Blend the bitmap buffer onto the final destination using the specified opacity level.

It is important to note that the opacity setting is applied as one of the last steps in this process.

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

Tips for disabling scrolling on a <div> using another <div> as a lock

I am facing an issue with a page where a div is appended to the body of an HTML. The problem is that there are two scrolls appearing - one on the new overlaying div and another behind it. Here is an approximate structure of the page, how can I ensure that ...

I encountered an issue where I am unable to subtract from jQuery's .outerHeight() within an if statement

I've been working on creating an ajax request that triggers when a div is scrolled to the bottom. I thought I had it figured out with this code, but I've run into an issue. Everything works fine without subtracting 100 from the elem.outerHeight() ...

Creating a custom arrow design for a select input field using CSS

I'm currently developing a website (using Wordpress with a custom theme) and I want to incorporate an up/down arrow in the select input field using CSS. The HTML code I have for creating the up/down arrow in the select input field is as follows: < ...

Is it still beneficial to incorporate image sprites in the design of a mobile web app?

As I work on developing a mobile web app, I find myself debating whether to use individual images or stick with image sprites similar to what I do for my desktop site. My main concern is the potential increase in file size from consolidating all the images ...

Can file input buttons be custom styled?

Since I am using Material-UI, the traditional methods are not working for me. I have a form with two buttons positioned next to each other. One button is an "Upload File" input for users to upload a file, and the other is a submit button. I want both butto ...

A unique and dynamic design concept for my website: a zigzagging structure

I am trying to achieve a layout similar to the one at the provided link, with variable sized div tags on the left and right edges. Can someone please assist me in styling the left and right sides accordingly? Key styles I have used: .rightside { margin-l ...

Having trouble with selecting checkboxes in a div using jQuery? While it may work in IE and Firefox, Chrome seems to be causing issues

In my div, I have several checkboxes placed under labels for formatting purposes. There is a list of checkbox names that need to be checked upon certain actions. Here is the list: var columns= ['2','5','4'] This is the curren ...

What is the main purpose of using the CSS transform:translate() property?

When CSS3 introduced animations with transition properties, it gave developers two main ways to change the position of an element. The first method involves setting the element's position as absolute and adjusting the left, right, top, and bottom prop ...

I am currently having issues with a PHP script I wrote for sending email, as it is

After creating a form and implementing a PHP script to send an email upon form submission, I encountered an issue where the "Thank you" message was displayed on a different HTML page, but the email wasn't sent to my account. I uploaded the files to t ...

How can I make a DIV occupy the entire vertical space of the page?

I am working on a Google Maps application that takes up the majority of the screen. However, I need to reserve a strip at the top for a menu bar. How can I ensure that the map div fills the remaining vertical space without being pushed past the bottom of ...

Guide to positioning the layout inflater on the right side

I am facing an issue with the layout inflater where the inflated layout appears in the center of the page instead of the intended right corner placement. I have attempted to modify the gravity to right, but it did not resolve the problem. Below is a snipp ...

Can you please provide me with detailed instructions on how to use the radio button?

As someone who isn't a professional coder, I dabble in creating code for fun. Right now, I'm working on a roleplay project on a website where each character has a designated "space" to input HTML and CSS code as a template. I've stumbled upo ...

What is the best way to crop an image to focus solely on the center portion?

Using Bootstrap 3, how can I display an image cropped in a .col-sm-6 grid column? The image is 720px wide. Typically, with the .img-responsive class, the image will resize proportionally when the display size changes. However, I want to crop the left and ...

The sticky positioning in <table> element fails to function properly in Firefox as well as Chrome version 58

Visit the website Scroll down until you see the "The First 40 Elements" table. Continue scrolling to reach the end of the page. In Chrome version 57, the table header stays sticky, but in Chrome 58 it does not. Interestingly, the table header also does n ...

Top Tip for conditionally rendering a styled component inside or outside a wrapper, depending on the screen width

Can anyone help me with this coding question? I'm currently trying to determine the most efficient way to conditionally place the code inside or outside of the wrapper. However, I am unsure what the best practice for this would be. This process seems ...

What is the best way to create a new column that wraps content from existing columns?

While working on some homework, I encountered an issue with flex-wrap. I have columns that I want to wrap into at least two columns, but instead, they are overflowing my container. Note: I am aware that this can be achieved with grid as well, but I wanted ...

What is the best way to trigger a PHP function using a button click event?

One of the functionalities I have is a reset button that's supposed to switch out the JSON data displayed here with a different dataset called defaultStats.json (that I've saved for this purpose). Here's a snapshot of what the current databa ...

Having trouble aligning input elements in the middle of a div container

Can anyone help me with centering elements inside a div? Check out this example: I created a wrapper for the number inputs and tried applying the text-center property on them, but it's not working. I also changed the display to block, but that doesn& ...

Is there a way to utilize jQuery to redirect to the href included in the HTML attachment?

I am looking to add a redirection feature to my website using the href provided in the code by jQuery. This will be done after playing an animation for better user experience. $(document).ready(function(){ $("a").click(function(event){ event.prev ...

Python code displays output directly on an HTML webpage

I have created a basic Python chatbot that performs calculations and responds to user input. The chatbot continuously runs in Python, checking previous responses for context. I want to make this chatbot available online and achieve the following: Send us ...