What is the best way to adjust the transparency of a <div>'s background without impacting its contents?

HTML

<div class="row Home">
      
      <div
        class="col right"
        style="background-image: url('./Images/car-2797169_1280.jpg')"
      >
        <div class="elementsOverlay d-flex justify-content-center align-items-center">
          <div class="d-flex flex-column-reverse">
            <div class="ps-4 mt-4">
              <button type="button" class="btn bookNow">Book Now</button>
            </div>
    
            <div class="ps-4 pt-5 pe-2">
              Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
              gravida nisl eget massa commodo, condimentum pharetra purus malesuada.
              Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi
              convallis id dolor nec dictum. Sed mollis scelerisque condimentum.
              Quisque viverra nisl vel diam hendrerit vestibulum. Cras augue ligula,
              consectetur eu eleifend a, viverra cursus dolor. Fusce gravida et
              lectus ut mollis. Donec pulvinar felis finibus mauris pretium
              efficitur. Donec in dui condimentum nunc tempus ultricies
            </div>
          </div>
        </div>
    </div>`

CSS

.right {
  background-size: cover;
  background-repeat: no-repeat;
  min-height: 100vh;
  opacity: 0.5;
  position: relative;
  color: white;
  text-shadow: 2px 2px 2px rgb(47, 45, 45);
}

.elementsOverlay {
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.2);
}

I've attempted to implement the methods suggested in other Stack Overflow threads by using argb to adjust the opacity, but unfortunately, it didn't have any effect on my website.

.elementsOverlay { background-color: rgba(0, 0, 0, 0.6) !important; }

Your assistance is greatly appreciated!

Answer №1

Give the CSS property backdrop-filter a try.

.right {
  backdrop-filter: opacity(50%);
}

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

An issue with the animation script in Ionic

I'm having trouble converting this to an Ionic application. Here's my code sample. Can anyone help me with putting this code correctly in Ionic? I'm trying to achieve something like this example <script src="https://cdnjs.cloudflare.com ...

Divider displayed between images in Internet Explorer 8

On my website, I have arranged four images in a square using the code below: <div id="tempo_main"> <div id="tempo_content"> <div style="text-align: center;z-index: 3;position: absolute;right:350px; left:350px; t ...

Integrating a $font-family-serif variable into Bootstrap 5

In my exploration of Bootstrap 5 documentation, I delved into the topic of typography and came across the files _variables.scss and _reboot.scss. I noticed that there exists a SASS variable $font-family-sans-serif for setting the font stack for sans serif ...

Guide to utilizing SVG animations for line drawing rather than just outlines

I've been experimenting with animating an SVG file to resemble the gif below, and I'm getting pretty close, but I seem to be encountering an issue where the outlines are drawn before being filled. I want the entire lines to be animated as shown i ...

Ways to align div elements

I am currently in the process of developing my own custom animation player. Utilizing Three.js for object rendering has been successful so far. However, the challenge lies in incorporating control options at the bottom of the player interface (such as play ...

Adjust the parent container to perfectly accommodate the child element

Is there a way to resize the container box to fit its dynamic content without using JavaScript? Here is the sample code for the problem: <div id="container"> <div id="content"></div> </div> #container { position: relativ ...

Strategies for avoiding text wrapping in Bootstrap labels on Firefox

Within my panel and panel-body, there are multiple span elements that display dynamically. These spans behave perfectly in Safari and Chrome, wrapping to the next line when needed. However, in Firefox, they overflow strangely. Here are the comparisons: Ch ...

Striving to convert Celsius to Fahrenheit using ReactJS

I am currently attempting to convert Celsius into Fahrenheit within this specific div. Despite being fairly new to React, I’m finding it challenging to determine where exactly to place the conversion calculation. return ( <div className="app& ...

What sets apart the usage of :host from its absence?

I'm finding it quite confusing to understand the usage of :host in Angular. For instance, let's consider a CSS file named a-component.component.css and its corresponding HTML file named a-component.component.html with a selector of app-a-compone ...

What is the correct way to include viewport width in pixels using CSS?

My div is set to a width of 50vw with padding of 25px on all sides. I am looking to add a fixed element to the right of it by increasing its width by 50vw and adding 25px. Can this be achieved using only CSS, or should I consider using Less? If so, how c ...

jQuery sidebar with a fixed position

Is there a way to implement a sidebar menu feature using jQuery that reappears on the left as the user scrolls down the page? You can see an example sidebar menu here. ...

Adding a scroll bar to a fixed container: tips and tricks

I am looking to implement a scrollbar in a fixed container for the cart products. The goal is to enable easy navigation through a large number of products added to the cart by scrolling within the container. Below is the HTML code snippet representing the ...

How can I use Bootstrap and PHP to style future posts in separate rows on a website?

I am attempting to design a categories navigation menu using Bootstrap 5. It consists of two columns, the first displaying featured posts and the second showing 5 recent posts. Here is an example of what I have tried, but it didn't work as expected b ...

Arrange elements side by side within siblings, while keeping the HTML structure intact

As evident from the code snippet, there are 2 dynamically generated flex divs (although there could be more). Is there a method to horizontally align items on larger screens without altering the HTML structure? I am seeking something similar to: https:/ ...

The footer is anchored at the bottom on one page but mysteriously relocates to the center on the next page

I've been working on creating a footer for my Angular application and here's the code for it: // HTML <footer class="footer"> // code for footer </footer> // LESS .footer { position: absolute; bottom: 0; width: 100% ...

What is the best way to transform all elements on a webpage into a dynamic scrolling marquee?

Is there a way to make every div in a web application scroll like a marquee? Perhaps by using a specific CSS class or other method? The application is built with Angular 4 and Bootstrap. ...

Is it feasible to overlay a PNG image on top of a button while still allowing the button to be clickable?

Can you place an image (.png) on top of a button and still make the button clickable? https://i.sstatic.net/9Z8nH.jpg ...

Is it possible to set a unique identifier in Vue.js that persists even after the page is reloaded?

Currently, I'm working on a small project diving into Vue js - a Habittracker. Unfortunately, there is a bug in my code. When the page is reloaded and new habits are added, the function that should change the background doesn't work as expected. ...

Maintaining the style of `li` elements within a `ul` list while ensuring they all

Struggling to create a menu list item with 4 items that won't fit on one line? Nested divs didn't work when adding padding. Here is my latest HTML and CSS: HTML: <div id="header"> <ul id="menu"> <li><a href="#"& ...

Display information in a detailed table row using JSON formatting

I have set up a table where clicking on a button toggles the details of the corresponding row. However, I am having trouble formatting and sizing the JSON data within the table. Is there a way to achieve this? This is how I implemented it: HTML < ...