Implementation of adding a mask layer effect when the CSS mouse hovers over the image

Implementation of adding a mask layer effect when the CSS mouse hovers over the image

First look at the effect:

A large picture wall insert picture description here

When the mouse moves over the image, add shadow effect + text/icon

insert image description here

The key to implementation is CSS opacity and hover . This article also mainly introduces the implementation of the mask layer.
HTML:

<div class="img_div">
   <img src="item.image_base64" @click="deleteImg" class="imgCSS">
   <div class="mask">
     <h3><Icon type="ios-trash-outline" size="40"></Icon></h3>
   </div>
 </div>

CSS: [Deleted some codes not related to the implementation of the above picture]

I think the key code is
The parent element img_div should have display: block; position: relative;
Child element mask layer position: absolute; opacity: 0; pointer-events:none;
When the mouse is hovering, opacity: 1;

Others can be improved according to business needs

It should be pointed out that the purpose of pointer-events:none is to solve the problem that when there is an absolute positioning of the mask layer, clicking on the image cannot trigger an event, such as the deleteImg event in the code

.img_div {
    border-radius: 10px;
    display: block;
    position: relative;
  }
  .imgCSS {
    height: 100%;
    width: 100%;
    border-radius: 10px;
    display: block;
    cursor: pointer;
  }
   .mask {
   position: absolute;
   background: rgba(101, 101, 101, 0.6);
   color: #ffffff;
   opacity: 0;
   top: 0;
   right: 0;
   width: 100%;
   height: 100%;
   border-radius: 10px;
   pointer-events:none;
 }
  .mask h3 {
    text-align: center;
    margin-top: 25%;
  }
  .img_div:hover .mask {
    opacity: 1;
  }

This is the end of this article about how to implement the CSS mask layer effect when the mouse hovers over an image. For more relevant CSS mouse hover image mask layer content, please search 123WORDPRESS.COM’s previous articles or continue to browse the related articles below. I hope that everyone will support 123WORDPRESS.COM in the future!

<<:  Things You Don’t Know About the CSS ::before and ::after Pseudo-Elements

>>:  Install Linux using VMware virtual machine (CentOS7 image)

Recommend

Introduction to JWT Verification Using Nginx and Lua

Table of contents Preface Lua Script nignx.conf c...

How to open the port in Centos7

The default firewall of CentOS7 is not iptables, ...

The use and methods of async and await in JavaScript

async function and await keyword in JS function h...

Detailed explanation of CocosCreator project structure mechanism

Table of contents 1. Project folder structure 1. ...

Zen HTML Elements Friends who use zen coding can collect it

html ¶ <html></html> html:xml ¶ <h...

Practice of using SuperMap in Vue

Table of contents Preface Related Materials Vue p...

Briefly describe the difference between MySQL and Oracle

1. Oracle is a large database while MySQL is a sm...

MySQL InnoDB transaction lock source code analysis

Table of contents 1. Lock and Latch 2. Repeatable...

CentOS 6-7 yum installation method of PHP (recommended)

1. Check the currently installed PHP packages yum...

Detailed explanation of uniapp painless token refresh method

When the front-end requests the interface, it is ...

Analysis and solution of data loss during Vue component value transfer

Preface In the previous article Two data types in...

CSS3 to achieve simple white cloud floating background effect

This is a very simple pure CSS3 white cloud float...