How to add color mask to background image in CSS3

How to add color mask to background image in CSS3

Some time ago, during development, I encountered a project that required adding a color mask to the background layer. Now I will specifically summarize the method of adding a color mask to the background layer.

Method 1: Overlay by positioning (pay attention to the hierarchy)

<div class="wrap1">
     <div class="inner"> </div>
</div>
.wrap1 {
    position: relative;
    width: 1200px;
    height: 400px;
    background: rgba(0, 0, 0, .5);
}

.wrap1 .inner {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background: url(ban8.jpg) no-repeat center center;
    background-size: cover;
    z-index: -1;
}

Method 2: Overlay through pseudo-elements

<div class="wrap2"></div>
.wrap2 {
    position: relative;
    width: 1200px;
    height: 400px;
    background: url(ban8.jpg) no-repeat center center;
    background-size: cover;
}

.wrap2::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    background-color: rgba(0, 0, 0, .5);
    z-index: 2;
}

Method 3: CSS3 color overlay background-blend-mode:multiply; (multiply)

<div class="wrap3"></div>
.wrap3 {
    position: relative;
    width: 1200px;
    height: 400px;
    background: url(ban8.jpg) rgba(0, 0, 0, .5) no-repeat center center;
    background-blend-mode: multiply;
}

Extension: Background blur and color overlay

.wrap4 {
    position: relative;
    width: 1200px;
    height: 400px;
    background: url(ban8.jpg) rgba(0, 0, 0, .5) no-repeat center center;
    background-blend-mode: multiply;
    filter: blur(2px);
    overflow: hidden;
}

Summarize

The above is the method of adding color mask to background images in CSS3 that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

<<:  Implementation ideas and steps for MySQL master-slave construction (multiple masters and one slave)

>>:  Summary of Vue first screen performance optimization component knowledge points

Recommend

Linux system AutoFs automatic mount service installation and configuration

Table of contents Preface 1. Install the service ...

Detailed analysis of SQL execution steps

Detailed analysis of SQL execution steps Let'...

Vue+ssh framework to realize online chat

This article shares the specific code of Vue+ssh ...

Brief introduction and usage of Table and div

Web front end 1 Student ID Name gender age 01 Zha...

SELinux Getting Started

Back in the Kernel 2.6 era, a new security system...

Convert XHTML CSS pages to printer pages

<br />In the past, creating a printer-friend...

Detailed use cases of vue3 teleport

Official Website https://cli.vuejs.org/en/guide/ ...

MySQL 8.0.15 installation and configuration tutorial under Win10

What I have been learning recently involves knowl...

Zabbix redis automatic port discovery script returns json format

When we perform automatic discovery, there is alw...

Vue keeps the user logged in (various token storage methods)

Table of contents How to set cookies Disadvantage...

Example code for implementing the "plus sign" effect with CSS

To achieve the plus sign effect shown below: To a...

What is web design

<br />Original article: http://www.alistapar...

Summary of javascript date tools

let Utils = { /** * Is it the year of death? * @r...