Example code for implementing a hollow mask layer with CSS

Example code for implementing a hollow mask layer with CSS

Contents of this article: Page hollow mask layer, page hollow mask guide layer, image hollow mask

Regular mask layer

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>Title</title>
    <style>
        .mask{
   position: absolute;
   width: 100%;
   height: 100%;
   top: 0;
   left: 0;
   background: rgba(0,0,0,0.4);
   display: flex;
   justify-content: center;
   align-items: center;
   z-index: 3;
  }
  .mask{
   position:fixed;
      top : 0;
      left : 0;
      bottom : 0;
      right : 0;
      background:rgba(0,0,0,.5); 
      /*background:hsla(0,100%,80%,0.5)*/
      /*background:#000; opacity:0.5; */
  }
  //Blur effect frosted glass effect.blur{
   -webkit-filter: blur(5px); /* Chrome, Opera */
   -moz-filter:blur(5px);
   -ms-filter:blur(5px);    
   filter: blur(5px);
  }
</style>
</head>
<style>

</style>
<body>

<div class='mask'></div>

</body>
</html>

The effect of the hollow mask layer is shown in the figure

Use box-shadow to achieve hollow mask guide layer effect

advantage:

  • Rounded corners are easily achieved;
  • Box-shadow will not affect the position of the element, and the positioning only needs to be written according to the position of the content.

Disadvantages: The shadow visible area cannot trigger the click event, so when you click any area of ​​the mask, it cannot be hidden.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>Title</title>
    <style>
        .guide{
      position: absolute;
      z-index: 2;

   top: 0px;
      left: 50%;
      transform: translateX(-50%);
      
      width: 50px;
      height: 50px;
      border-radius: 50px;
      border: 3px solid #2353FA;
      
      box-shadow: 0px 0px 0px 1000px rgba(0,0,0,.75);
      box-sizing: border-box;
    }
    </style>
</head>
<style>
</style>
<body>
<div class='guide'></div>
</body>
</html>

Use border to achieve hollow mask guide layer effect

Disadvantages: Large amount of code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>Title</title>
    <style>
     .guide{
      position: absolute;
      z-index: 2;
      .opacityEle{
        border: 700px solid rgba(0,0,0,0.75);
        width: 50px;
        height: 50px;
        position: relative;
        top: -700px;
        left: -538px;
        border-radius: 50%;
        .ele{
          width: 50px;
          height: 50px;
          border: 3px solid #0B6EFF;
          border-radius: 25px;
          box-sizing: border-box;
        }
      }
    }
    </style>
</head>
<style>

</style>
<body>

<div class='guide'>
 <div class='opacityEle'>
  <div class='ele'></div>
 </div>
</div>
</body>
</html>

This concludes this article about the sample code for implementing a hollow mask layer with CSS. For more information on CSS hollow mask layers, please search previous articles on 123WORDPRESS.COM or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  How to modify the default submission method of the form

>>:  How to solve the problem of absolutely positioned elements mysteriously disappearing or being blocked in IE6/7

Recommend

Vue global filter concepts, precautions and basic usage methods

Table of contents 1. The concept of filter 1. Cus...

Two methods to disable form controls in HTML: readonly and disabled

In the process of making web pages, we often use f...

Detailed explanation of three ways to cut catalina.out logs in tomcat

1. Log4j for log segmentation 1) Prepare three pa...

Can MySQL's repeatable read level solve phantom reads?

introduction When I was learning more about datab...

Detailed explanation of selinux basic configuration tutorial in Linux

selinux ( Security-Enhanced Linux) is a Linux ker...

How to Dockerize a Python Django Application

Docker is an open source project that provides an...

Native JS to implement breathing carousel

Today I will share with you a breathing carousel ...

Detailed explanation of CSS weight value (cascading) examples

•There are many selectors in CSS. What will happe...

Linux system (Centos6.5 and above) installation jdk tutorial analysis

Article Structure 1. Preparation 2. Install Java ...

JavaScript to achieve JD.com flash sale effect

This article shares the specific code of JavaScri...

jQuery implements employee management registration page

This article example shares the specific code of ...

Share JS four fun hacker background effect codes

Table of contents Example 1 Example 2 Example 3 E...