How to implement an overlay fix in HTML

Here is a problem I need help with:

The image has an overlay with a lighter black background applied. However, the text is also becoming overlaid, which is not the desired effect.

Can anyone provide a solution to fix this issue?

Answer №1

The container with the class .text currently has an opacity of 0.5, which is affecting its sibling content. One solution to this issue is to use rgba color values instead of opacity in the container's background property.

.text {
background-color: rgba(0, 0, 0, 0.5);
}

Another option is to use a 1x1 semi-transparent png image as the background for the container. Additionally, you can create an overlay div that is absolutely positioned within the .text container. This overlay div should have a lower z-index value so it remains behind other content. Here is an example:

HTML

<div class="overlay">&nbsp;</div>

Insert the .overlay div at the bottom of the .text container.

CSS

.text {
  position:relative;
  z-index:10;
}

.overlay {
  position:absolute;
  top:0; right:0; bottom:0; left:0;
  background-color:black;
  opacity:0.5;
  z-index:1;
}

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

What is the best way to locate the offspring of a parent div using its data attribute?

If I have a container div called dvMainDiv with multiple child divs inside it, all added programmatically, how can I retrieve a specific child div based on its data-id attribute? <div id="dvMainDiv" class="dvMainDiv"> <div id="dvChildDiv" cla ...

use jQuery to retrieve the value of an attribute

I am having trouble extracting the value of the name attribute from this HTML code: <select id='id_select'> <option name='nm_opt' value='23'>Val1</option> <option name='nm_opt2' value='16 ...

Is it possible to convert nested CSS into Material-UI's CSS in JS method?

Here is the code for embedding an iframe: <style>.embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; } .embed-container iframe, .embed-container object, .embed-container embed { position: abso ...

How to perfectly position an image within a fixed full screen container

When you click on a thumbnail image, a full-screen overlay with a larger version of the image will be triggered using JavaScript. To ensure that the image is centered and resized inside the black overlay when the browser window size changes, I attempted t ...

What is causing the compatibility issue between Ant Design V5 styles and NextJS?

Description In my NextJS project, I am using the Ant Design V5 framework with multiple pages. However, I am facing an issue where the styles are only working correctly on one page and not being applied properly on other pages. Despite referring to the off ...

Choose the singular Element lacking both a class or an ID

I came across this and that question, however, they are both focused on Javascript. I am searching for a way to target the lone div that does not have an ID or Class assigned to it. For instance: <body> <div class="X" ... /> <div class="Z ...

The Angular 7 template falls short of occupying the entire page

I am currently working on converting an HTML page into my Angular project. While it functions correctly in the HTML version, it does not fill up the entire page when transferred to Angular. You can view an example of this issue on StackBlitz at the followi ...

Stylish CSS Tricks with Font Awesome Icons

In my project, I am utilizing Font Awesome SVG with JavaScript multiple times. Currently, I am working on creating a button that displays an arrow icon to the right of the text when hovered over. However, I encountered an issue where there is a blank squar ...

demonstrate the worth within a PHP form

Hey there! In order to use all available form controls and display the processed values correctly, I have included the following code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> < ...

Tips for Automatically Keeping Bootstrap Dropdown Open When Selecting an Option

My bootstrap dropdown features a select box with specific options that I want to keep visible. However, when I click on it, the drop-down closes unexpectedly. How can I prevent the drop-down from closing when clicking on the select box? Check out this boo ...

Load a URL using JQuery and place the content into the specified target element within the current

While working on a project, I encountered an issue with loading external content from a URL using jQuery's .load() function. This functionality was triggered by an onclick event and the parent document was a prompt window. The following is the HTML c ...

Which domain do I need to use: Google or my own, in order to bypass the Access Denied issue in JQuery

I'm currently experiencing a puzzling issue with my website while using Internet Explorer. Despite loading fine in other browsers, I keep encountering a permission denied error within my JQuery code. What's even more perplexing is that this error ...

Issue with a Bootstrap panel displaying incorrect border formatting

I am currently working with Angular UI Bootstrap and facing an issue with an accordion component. Everything works perfectly fine in the development environment with the full version of the Bootstrap Cerulean file. However, when I minify the CSS file for p ...

Showing a notification that is persistent and not dismissible

Hello everyone! I've been struggling with a problem on the RPS project for quite some time now. The issue arises when I try to display a message for a tie in the game, but I can't seem to find a solution to make it disappear when the round is not ...

The code provided creates a web form using HTML and ExpressJS to store submitted information into a MongoDB database. However, there seems to be an issue with the 'post' method, while the 'get' method functions correctly

When I try to submit entries (name, email, address) on localhost:3000 in the browser, the 'post' function is not creating an object in the mongo database even though it works from the postman. The browser displays an error message saying "unable ...

In search of advice on the best web-based database management technology

I'm looking to create a prototype for a web-based database manager, similar to the desktop version in the image below, with specific features in mind. Initially, the schema will be provided through a flat file. Considering HTML5 as an option, I am a ...

Keep bootstrap content aligned to the left

I am working on creating a webpage using bulma/bootstrap and my goal is to have some text positioned on the left side of the screen. I want this text to be displayed in the red area and to stay fixed in place when I scroll down, similar to a side panel. ...

Displaying Bootstrap Quotes in a vertical orientation on the screen

https://i.sstatic.net/90qYG.pngI'm struggling to make a long quote display wider horizontally and haven't been able to figure it out. Below are the current HTML and CSS scripts I have. I simply want the text to be shown wider than it currently is ...

Is it possible to use an angular expression as the ng-click function?

I have been searching everywhere for the answer to this question. Within my code, there is an angular object called column.addOnParams. This object includes a child element named rowClick, which can be accessed using column.addOnParams.rowClick. The val ...

I am unable to pass a variable through a callback, and I cannot assign a promise to a

Currently, I am facing a challenge with my code where I need to loop through a hard-coded data set to determine the distance from a user-entered location using Google's web API. The issue lies in passing an ID variable down through the code so that I ...