Home >Web Front-end >CSS Tutorial >How Can I Overlay a Translucent Color Over a Background Image Using CSS?

How Can I Overlay a Translucent Color Over a Background Image Using CSS?

DDD
DDDOriginal
2024-12-13 17:40:14559browse

How Can I Overlay a Translucent Color Over a Background Image Using CSS?

Layer Translucent Color over Background Image

You mentioned encountering an issue while attempting to overlay a translucent color layer over a background image using CSS. Let's explore how to achieve this effect effectively.

Your initial approach using both background-image and background-color is technically correct but doesn't produce the desired result because the background-color property overrides the background image. To resolve this, you can consider the following alternative:

background-image: url('../img/bg/diagonalnoise.png');
background-color: rgba(248, 247, 216, 0.7);
background-blend-mode: overlay;

The background-blend-mode property allows you to specify how multiple background layers interact. In this case, the overlay blend mode superimposes the translucent color onto the background image, creating a semi-transparent layer.

Another approach that solely relies on CSS is to utilize the box-shadow property:

box-shadow: inset 0 0 0 1000px rgba(0,0,0,.2);

By specifying an inner, transparent box shadow, you can effectively create a colored layer that overlays the background image. This technique has the advantage of being a pure CSS solution, without requiring any additional HTML elements.

The above is the detailed content of How Can I Overlay a Translucent Color Over a Background Image Using CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn