css设置让整个盒子的内容渐变透明(非颜色渐变透明)

css设置让整个盒子的内容渐变透明(非颜色渐变透明)

效果

核心css代码

css 复制代码
/* 设置蒙版上下左右渐变显示 */
mask-image: linear-gradient(to right, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) 10%, rgba(0, 0, 0, 1) 90%, rgba(0, 0, 0, 0) 100%),
      linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) 10%, rgba(0, 0, 0, 1) 90%, rgba(0, 0, 0, 0) 100%);
mask-composite: intersect;
html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }
    .f-c-c {
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .content {
      width: 100vw;
      height: 100vh;
    }
    .skyblue {
      width: 500px;
      height: 500px;
      background-color: skyblue;
      /* 设置蒙版上下左右渐变显示 */
      mask-image: linear-gradient(to right, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) 10%, rgba(0, 0, 0, 1) 90%, rgba(0, 0, 0, 0) 100%),
      linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) 10%, rgba(0, 0, 0, 1) 90%, rgba(0, 0, 0, 0) 100%);
      mask-composite: intersect;
    }
    .pink {
      width: 200px;
      height: 200px;
      background-color: pink;
    }
    .pink {
      width: 200px;
      height: 200px;
      background-color: pink;
      /* 设置蒙版上下左右渐变显示 */
      mask-image: linear-gradient(to right, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) 10%, rgba(0, 0, 0, 1) 90%, rgba(0, 0, 0, 0) 100%),
      linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) 10%, rgba(0, 0, 0, 1) 90%, rgba(0, 0, 0, 0) 100%);
      mask-composite: intersect;
    }
    .yellow {
      width: 100px;
      height: 100px;
      background-color: yellow;
    }
  </style>
</head>
<body>
  <div class="content f-c-c">
    <div class="skyblue f-c-c">
      <div class="pink">
        <div class="yellow"></div>
      </div>
    </div>
  </div>
</body>
</html>
相关推荐
蓝胖子的多啦A梦18 分钟前
低版本Chrome导致弹框无法滚动的解决方案
前端·css·html·chrome浏览器·版本不同造成问题·弹框页面无法滚动
玩代码20 分钟前
vue项目安装chromedriver超时解决办法
前端·javascript·vue.js
訾博ZiBo37 分钟前
React 状态管理中的循环更新陷阱与解决方案
前端
StarPrayers.1 小时前
旅行商问题(TSP)(2)(heuristics.py)(TSP 的两种贪心启发式算法实现)
前端·人工智能·python·算法·pycharm·启发式算法
一壶浊酒..1 小时前
ajax局部更新
前端·ajax·okhttp
DoraBigHead2 小时前
React 架构重生记:从递归地狱到时间切片
前端·javascript·react.js
ะัี潪ิื3 小时前
精灵图(雪碧图)的生成和使用
java·css
彩旗工作室3 小时前
WordPress 本地开发环境完全指南:从零开始理解 Local by Flywhee
前端·wordpress·网站
iuuia3 小时前
02--CSS基础
前端·css
kyle~3 小时前
Qt---setAttribute设置控件或窗口的内部属性
服务器·前端·c++·qt