Overlay with a progress bar that obscures visibility

I'm dealing with a progress bar that needs to be displayed on top of an overlay. If you take a look at this jsfiddle, you can see the issue.

Here's the markup:

<div class="overlay mouse-events-off">
    <div class="progress progress-striped active">
        <div class="bar" style="width: 40%;"></div>
    </div>
</div>

And here's the CSS:

.overlay { background-color: black; position: fixed; top: 0; right: 0; bottom: 0; left: 0; opacity: 0.2; z-index: 100; }
.progress { position: absolute; top: 50%; left: 35%; width:300px; height:20px; z-index:101; opacity:1.0; }

The progress bar also has a 20% opacity, which is causing issues.

I did find a workaround by moving the <div> holding the progress bar outside of the overlay, but it feels like unnecessary extra markup.

Here's the updated working markup:

<div id="progress" style="display:none;">
    <div class="progress progress-striped active glow">
        <div class="bar" style="width: 40%;"></div>
    </div>
    <div class="overlay mouse-events-off"></div>
</div>

Is there a more elegant solution using just CSS?

Answer №1

When utilizing the opacity property, all content inside that particular element will be impacted without any workarounds available.

You have a couple of options to achieve this effect:

Option 1: Progress Outside

Place the progress bar outside the overlay and adjust its position to be centered on top of the overlay.

.progress {
    position: absolute;
    top: 50%;
    left: 50%;
    width:300px;
    height:20px;
    margin:-10px 0 0 -150px; //half width left, half height top
    z-index:101;
    opacity:1.0;
}

Option 2: Keeping as is

Rather than applying opacity directly to the element itself, apply it to the background instead!

.overlay {
    background-color: black; /*for older browsers*/
    background-color: rgba(0,0,0,.2); /*newer browsers will override the 'black' color with rgba*/
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    /*opacity:0.2; avoid using opacity!*/
    z-index: 100;
}

For the second approach, check out the jsFiddle link provided: http://jsfiddle.net/Qpv4E/2/

Answer №2

Here is a similar query: Avoid inheriting child opacity from parent in CSS

Expectantly, RaphaelDDL's solutions will provide assistance.

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

Looking for an Angular Material component that displays a list of attributes?

I am trying to create a dynamic list of properties in Angular using Material Design that adjusts for different screen sizes. For example, something similar to this design: https://i.stack.imgur.com/EUsmV.png If the screen size decreases, the labels shou ...

The Weglot country selector is not properly aligned with the rest of the content and its hover

Our Woocommerce store is now multilingual thanks to the weglot plugin. In the desktop view, we have integrated the country selector next to the shopping cart. For mobile view, we placed the HTML Widget in the header with some surrounding code: <div clas ...

Unable to apply 3rd condition with ngClass into effect

I've been attempting to incorporate a third condition into my ngClass. Initially, I managed to get two classes working in my ngClass to change the row colors alternately. [ngClass]="{ totalrow:i%2 != 0, odd:i%2 == 0}" Now, I'm trying to introdu ...

Ensure that the divs are properly aligned and construct columns within a single column

I've been working on creating a step bar that needs to adapt to any number of steps provided by the backend. Here's what I have so far: https://i.sstatic.net/cj4qZ.png It looks fine, but connecting the circles with bars would be beneficial. How ...

Styling Material UI components with CSS is a great way to

I'm facing difficulties while working with Material UI components. Currently, I have a Material UI table and I want to center-align the text within it. The standard CSS of Material UI contains an element named MuiTableCell-root-60 which has a text-a ...

The div is not showing the image as expected

Having some trouble creating a slideshow within my angular application. Struggling to get the images to display in the html code. To tackle this, I decided to create a separate component specifically for the slideshow (carousel.component). In the main app ...

How can I style the inner div by adding a class to the first div?

In my project, I have a list of elements that are generated dynamically, all styled the same way but with different content. The first element has a specific styling, and if it doesn't render, I want the second element to inherit that styling. < ...

Ways to align text within a table cell on a background using CSS

I'm attempting to print jukebox strips with designated corner markings. The code I have written generates the HTML page for displaying the strips, allowing users to then print them. Jukeboxes typically feature selection buttons labeled ABCDEFGHJK and ...

What role does the sequence play in matrix transitions that involve rotating and translating simultaneously?

Attempting to animate a matrix3d with both rotation and translation concurrently has yielded unexpected results for me. It seems that changing the order of applying rotation and translation produces vastly different outcomes. http://jsfiddle.net/wetlip/2n ...

Hide the footer DIV in CSS by making it disappear with a height of 100%

I'm currently facing an issue with my CSS layout. Despite managing the problem in IE and seeing everything work well, the footer container has mysteriously disappeared! I've attempted to recode the CSS without success, even after trying for days ...

Dynamic CSS columns with a set width on the left and right sides

Dividing my background into two parts has been a challenge. Background Image #1 Endlessly Repeating Background Image #1 Background Image #2 Endlessly Repeating Background Image #2 In CSS, creating a background with multiple elements is not as simple as i ...

Tips for passing a timestamp to a Postgresql DB using a Button in a Form instead of a traditional rails time_select box

I am currently developing a CAD App in Rails 4 with Ruby 2. The goal is to provide users with a button on the screen to log an on-scene time and clear scene time, especially since most users will be using touch screen computers. Instead of using the defaul ...

What causes certain content to be inaccessible when using Safari?

When I visit this page using Safari or my iPhone, the list of social network members does not appear. Can anyone explain why this might be happening? I am unable to figure out the reason behind this issue. Thank you in advance for your help! ...

A guide to adjusting the size of a mat-button using an svg mat-icon

I have PrimeNg and Angular Materials buttons on the same td. I am attempting to resize my mat-buttons to match the size of my pButtons but they are not adjusting properly. Should I consider using a different type of button with my icon? HTML <button ma ...

The CSS selectors wrapped in jQuery vary between Chrome and Internet Explorer 11

When utilizing a jquery wrapped css selector such as $($("#selector").find('input[type="textarea"])'), I am able to input values into the textarea in Chrome using $($("#selector").find('input[type="textarea"]).val(someValue)') but encou ...

Is there a way to show output on render rather than using console.log in node.js?

I have successfully sorted the objects as shown in the link below. My next challenge is to integrate the sorted object into my render function rather than just using console.log(). I'm uncertain if converting it back into an object is the right appro ...

The ">" CSS child selector does not seem to be functioning correctly with specific properties

While experimenting with applying CSS properties to direct child elements of a parent element using ">", I noticed that it works smoothly with certain properties like borders, but not so much with font-related properties such as color and font-weight. ...

Stripping out only the position attribute using jQuery

I have implemented a code with the following characteristics: The navigation items' texts are hidden behind certain Divs, which I refer to as Navigation Divs. When the mouse hovers over these pixels (navigation Divs), the text that is behind the ...

Adjust the size of the HTML input font to decrease as additional text is entered

Is it possible to create an HTML text field that automatically adjusts the font size when the user types more characters than it can display? I know Acrobat has this feature for forms, but I'm looking to implement it in HTML. So, imagine having a te ...

Techniques for breaking down large CSS files into modules and combining multiple smaller CSS files

My website's CSS file is currently massive, containing site-wide selectors in a file named Mondo.css. While this setup has been effective for ensuring users only need to download the file once, I've recently developed a widget that requires its o ...