If a div sets background-color and background-image at the same time, the color is below the img layer and the masking effect cannot be achieved. Therefore, you need to create another div as its child div, and then set the background color of the child div. There are two methods: The first one, the code is as follows: css: .wrap{ position: relative; background: url(i/pic4.jpg) no-repeat; -webkit-background-size: 100%; background-size: 100%; } .warp-mask{ height:100%; width:100%; background: rgba(0,0,0,.4); } html: <div class="wrap"> <div class="wrap-mask"></div> </div> The second method is to set it through the after pseudo element. The code is as follows: css: .wrap{ position: relative; background: url(i/pic4.jpg) no-repeat; -webkit-background-size: 100%; background-size: 100%; } .wrap-mask:after{ position: absolute; top: 0; left: 0; content: ""; background-color: yellow; opacity: 0.2; z-index: 1; width: 100%; height: 100%; } html: <div class="wrap"> <div class="wrap-mask"></div> </div> Summarize The above is what I introduced to you about using background-color through CSS to add a mask effect to the background image. 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! |
<<: Detailed explanation of the decimal padding problem of decimal data type in MySQL
>>: CSS and HTML and front-end technology layer diagram
In order to extend the disk life for storing audi...
I installed IE8 today. When I went to the Microso...
1. Please download the Busybox source code online...
Using Javascript to implement countdown to close ...
Previously, I introduced the use of the charAt() ...
Table of contents Preface text 1. Install styleli...
Docker is a management tool that uses processes a...
Overview What is harbor? The English word means: ...
1. Overview of SQLException When an error occurs ...
When the front-end requests the interface, it is ...
The purpose of setting up MySQL query cache is: C...
First, you need to download and install Navicat f...
Table of contents 1. Calculated properties 1.1 Ba...
Today I installed the MySQL database on my comput...
1. Reverse proxy example 1 1. Achieve the effect ...