Add a partially see-through overlay to the background image

I'm designing a webpage that requires a background image with a semi-transparent black overlay on top (rgba 0 0 0 0.5).

Originally, I tried this approach:

<body id="body-pd" style="background: url('./img/Home e Roleta.png') no-repeat center center fixed; background-size: cover; box-shadow: inset 0 0 0 1000px rgba(0,0,0,.5);">

At first, it seemed to be working fine. However, as I started developing larger pages for the site, I noticed that when scrolling down, the semi-transparent cover does not move along:

https://i.sstatic.net/9jxMo.png

I searched online for a solution but couldn't find any relevant discussions.

Does anyone have any suggestions for solving this issue?

Here is the full code (includes Bootstrap 5):

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />

    <link href="./css/custom.css" rel="stylesheet">
    ...

</head>

<body id="body-pd" style="background: url('./img/Home e Roleta.png') no-repeat center center fixed; background-size: cover; box-shadow: inset 0 0 0 1000px rgba(0,0,0,.5);">
    ...
</body>

</html>

CSS:

@import url("https://fonts.googleapis.com/css2?family=Montserrat&display=swap");
...

@media (min-width: 576px) { 
    .game-col {
        border-left: 1px solid var(--white-color);
    }
    
    .game-block {
        border-bottom: 1px solid var(--white-color);
    }    
    .game-top {
        border-top: none;
    }
}

...

Answer №1

Have you considered incorporating the CSS filter property for your background image? Utilizing filter: brightness(0.5); or filter: opacity(0.5); can create a stylish semi-transparent black effect on your image.

To learn more about the CSS filter property, visit: https://developer.mozilla.org/en-US/docs/Web/CSS/filter

Answer №2

Have you considered utilizing a linear-gradient in combination with a background-image by using this setup?

background-image: linear-gradient(rgba( 255, 255, 255, 0.7), rgba( 255, 255, 255, 0.7)), url("./img/Welcome and Roulette.png");

By keeping the colors consistent (rgba( 255, 255, 255, 0.7)), the shades will remain constant and become part of the overall background-image.

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 maintaining the active tab in Jquery even after the page is reloaded, especially for tabs that are constantly changing

$(document).ready(function(){ $('.scroll_nav li a').click(function(){ $('li a').removeClass("active_scroll"); $(this).addClass('active_scroll'); $('ul li .btn-br_all_gun').click(function(){ ...

Choose to conceal beneath the table within Bootstrap 4

As a budding web developer, I am currently using Bootstrap 4 in my project. If you take a look at my preview by clicking here and then selecting "Liczba sztuk," you'll notice that I am facing an issue. The items within the select dropdown are gettin ...

Problem with the appearance of the drop-down menu

After a few dedicated weeks on a Web application project, I am currently tackling the challenge of a drop-down menu. Despite its functionality, there are two specific points I need help with: When expanding the menu by selecting a main item, I want to pr ...

What is the best way to align a collection of images in HTML and CSS?

Struggling to center five PNG images on a simple website for a friend. Previously, using display: block; and margin: auto; for one picture worked, as shown below. However, my current code: .middleContent{ width: 100%; top: 50px; p ...

Image hover effect displayed when hovering over an image

Is it possible to create a hover effect using purely CSS when hovering over an image, like in this example: https://i.sstatic.net/jjAWm.jpg I've come across several similar examples online, but they all seem to rely on jquery or javascript. I'm ...

Removing HTML tags from a string while preserving specific tags in JavaScript

Here is a JavaScript string that I am working with: var test = "<p>test</p> FOLER.PRODUCTS<12345><level-2>"; I'm trying to remove the HTML tags from the string because the service I'm using doesn't accept them. Here ...

If I create an App with Phonegap, HTML5, and Websql, what happens to the app's data when the user restarts their mobile device?

My application utilizes HTML5's WebSQL to store temporary notes and bookmarks, which will later be synchronized with the server. I am curious whether data stored in WebSQL will be lost upon mobile restart or cache clear, similar to how browsers on ph ...

Obtain the row ID from a database by selecting checkboxes

I am facing a challenge when trying to remove a row from my MS Access database using checkboxes on my JSP page. Each row in the displayed database has a checkbox, but I am struggling to retrieve the rowId and link each checkbox with its respective row. Any ...

Merging Fewer with Visual Studio 2012

Combining all Less files into a single stylesheet? After following the instructions in the above link, I have successfully merged my Less files together for easier CSS reading during development. However, I would like to ensure that end users only need to ...

Tips for positioning bootstrap-vue dropdown button items evenly

Can anyone help me align the dropdown button child items horizontally? I've tried customizing it with CSS but no luck. The control link can be found here Check out a sample on Js Fiddle here This is how I expect the design to look like: https://i.s ...

Troubleshooting Date Problems in Angular

When using the HTML5 date picker, I have encountered an issue where after choosing a date, the ng-model displays an older date instead of the current one selected. <input type="date" ng-model="dateModel" /> For example, when selecting the current d ...

Is it possible to line up two divs perfectly?

Hey there, I'm still trying to get the hang of CSS and using Dreamweaver CS6's fluid grid layout. In my attempt to create a header with two divs inside it - headerleft for an image and headerright for text - I've run into some alignment issu ...

How can I remove the gaps between Bootstrap panels on a website?

The Issue https://i.stack.imgur.com/I5EFR.png My problem is with the spacing between the panels, highlighted in red. I've attempted to remove them by using the following CSS: .panel { margin-top: 0; margin-bottom: 0; padding-top: 0; ...

jquery: displaying repeated divs on mouse hover - a tutorial

Let's say we have a div like this: <div class="y1"> <img src="i/o.png" /> </div> Also, we have this div for pre-loading: <!-- pre load --> <div class="p1" style="display:none"> <h5 class="ob">Title</h5> < ...

Dynamic and uniform height for a group of containers

Imagine three boxes lined up, each with an image and a title inside. I can adjust the height using the height property to make them all the same height. However, in a Responsive view, when the boxes shrink, their fixed height can cause extra white space to ...

The DIV Card has been displaced into a different row

https://i.sstatic.net/sdUB6.png I'm struggling to align my div card next to another card without it getting distorted. The first one looks fine, but I can't figure out how to position the next one beside it... $sql = "SELECT * FROM posts WHERE ...

Why does the second JavaScript form validation not function correctly when compared to the first?

Here is a form that I have created: <form action="next.html" id="userInput" method="post" onsubmit="return validate();"> Age: <input type="text" name="age" id="age"/> function validate() { var age = document. ...

Adjusting Font Sizes with Bootstrap 4 Media Queries: A Simple Guide

I recently incorporated Bootstrap into my project, but I've encountered an issue with the fixed heading sizes. I'm attempting to modify the font size of my project, especially because the h1 and h2 text appears overly large on mobile devices. Str ...

The image disappears when I click on a link and then return to the main page, but this only happens in Mozilla Firefox

Upon opening the main page, everything functions flawlessly. However, if I navigate to another page through one of my href links and then return to the main page, my div with the class "bild" disappears. Oddly enough, this issue only occurs in Mozilla Fire ...

Incorporate a curved progress line into the progress bar

Currently, I am working on creating a customized progress bar: .create-progress-bar { padding: 0 !important; margin: 25px 0; display: flex; } .create-progress-bar li { display: flex; flex-direction: column; list-style-type: none ...