CSS realizes the mask effect when the mouse moves to the image

CSS realizes the mask effect when the mouse moves to the image

1. Put the mask layer HTML code and the picture in a div

I put it in .img_div.

<div class="img_div">
    <img src="./images/paella-dish.jpg">
 
        <a href="#">
            <div class="mask">
               <h3>A Picture of food</h3>
                </div>
        </a>
</div>

2. Add styles to images and mask layers

Image: relative

Mask layer: absolute

Make the two styles overlap.

When the mouse is not on the image, the mask layer does not display .mask { opacity: 0; } .

.img_div {
    margin: 20px 400px 0 400px;
    position: relative;
    width: 531px;
    height: 354px;
}
.mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 531px;
    height: 354px;
    background: rgba(101, 101, 101, 0.6);
    color: #ffffff;
    opacity: 0;
}
.mask h3 {
    text-align: center;
}

3. Use hover

Change the transparency to make the mask layer show through.

.img_div a:hover .mask {
    opacity: 1;           
}

Effect picture:

Summarize

The above is the CSS that I introduced to you to realize the mask layer effect when the mouse moves to the 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!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

<<:  A detailed introduction to for/of, for/in in JavaScript

>>:  HTML Self-study Journey (I) Basic Elements and Attributes Practice (Write Your Own Code)

Recommend

Getting Started Tutorial on Using TS (TypeScript) in Vue Project

Table of contents 1. Introducing Typescript 2. Co...

CSS navigation bar menu with small triangle implementation code

Many web pages have small triangles in their navi...

How to manage cached pages in Vue

Table of contents Problem 1: Destruction 1. How t...

Sample code for automatic web page refresh and automatic jump

Automatic web page refresh: Add the following code...

What hidden attributes in the form can be submitted with the form

The form elements with visibility=hidden and displ...

Implementation of Nginx Intranet Standalone Reverse Proxy

Table of contents 1 Nginx Installation 2 Configur...

Detailed analysis of binlog_format mode and configuration in MySQL

There are three main ways of MySQL replication: S...

Compile CPP files using G++ in Ubuntu

When I used g++ to compile the cpp file for the f...

How to hide a certain text in HTML?

Text hiding code, hide a certain text in HTML Copy...

Summary of some small issues about MySQL auto-increment ID

The following questions are all based on the Inno...

How to clean up data in MySQL online database

Table of contents 01 Scenario Analysis 02 Operati...

MySQL concurrency control principle knowledge points

Mysql is a mainstream open source relational data...