温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

css如何实现缕空遮罩层

发布时间:2021-03-18 11:24:24 来源:亿速云 阅读:512 作者:小新 栏目:web开发

小编给大家分享一下css如何实现缕空遮罩层,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

常规遮罩层

<!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{
   -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>

镂空遮罩层效果如图

css如何实现缕空遮罩层

使用box-shadow实现镂空遮罩引导层效果

优点:

  • 圆角轻松实现;

  • box-shadow 不会影响元素位置,定位只需要根据 content 的位置写。

缺点:阴影可视区域无法触发click事件,因此,当点击蒙层任意区域,无法隐藏。

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

使用border实现镂空遮罩引导层效果

缺点:代码量大

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

看完了这篇文章,相信你对“css如何实现缕空遮罩层”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

css
AI