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

Vue elementUI implements tree structure table and lazy loading

Table of contents 1. Achieve results 2. Backend i...

How to install tomcat8 in docker

1. Install tomcat8 with docker 1. Find the tomcat...

Basic structure of HTML documents (basic knowledge of making web pages)

HTML operation principle: 1. Local operation: ope...

Detailed discussion on the issue of mysqldump data export

1. An error (1064) is reported when using mysqldu...

CentOS7 installation zabbix 4.0 tutorial (illustration and text)

Disable SeLinux setenforce 0 Permanently closed: ...

Detailed explanation of the use of the clip-path property in CSS

Use of clip-path polygon The value is composed of...

MariaDB under Linux starts with the root user (recommended)

Recently, due to the need to test security produc...

Solution to css3 transform transition jitter problem

transform: scale(); Scaling will cause jitter in ...

2 methods and precautions for adding scripts in HTML

How to add <script> script in HTML: 1. You c...

Definition and usage of MySQL cursor

Creating a Cursor First, create a data table in M...

Details of the order in which MySQL reads my.cnf

Table of contents The order in which MySQL reads ...

JavaScript canvas to achieve raindrop effects

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...