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

CSS3 realizes draggable Rubik's Cube 3D effect

Mainly used knowledge points: •css3 3d transforma...

Use Element+vue to implement start and end time limits

This article example shares the specific code for...

Vue components dynamic components detailed explanation

Table of contents Summarize Summarize When the ar...

js memory leak scenarios, how to monitor and analyze them in detail

Table of contents Preface What situations can cau...

Using puppeteer to implement webpage screenshot function on linux (centos)

You may encounter the following problems when ins...

How to build lnmp environment in docker

Create a project directory mkdir php Create the f...

MySQL 5.7.13 installation and configuration method graphic tutorial on Mac

MySQL 5.7.13 installation tutorial for Mac, very ...

Vue element implements table adding, deleting and modifying data

This article shares the specific code of vue elem...

js development plug-in to achieve tab effect

This article example shares the specific code of ...

How to use Webstorm and Chrome to debug Vue projects

Table of contents Preface 1. Create a new Vue pro...

Nginx configuration file detailed explanation and optimization suggestions guide

Table of contents 1. Overview 2. nginx.conf 1) Co...

How to build pptpd service in Alibaba Cloud Ubuntu 16.04

1. To build a PPTP VPN, you need to open port 172...

Explanation of the process of docker packaging node project

As a backend programmer, sometimes I have to tink...

MySQL 8.0.11 installation summary tutorial diagram

Installation environment: CAT /etc/os-release Vie...