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>
相关推荐
uwvwko9 分钟前
BUUCTF——web刷题第一页题解
android·前端·数据库·php·web·ctf
有事没事实验室37 分钟前
CSS 浮动与定位以及定位中z-index的堆叠问题
前端·css·开源
2501_915373881 小时前
Vue路由深度解析:Vue Router与导航守卫
前端·javascript·vue.js
小妖6661 小时前
前端表格滑动滚动条太费事,做个浮动滑动插件
前端
读心悦1 小时前
5000 字总结CSS 中的过渡、动画和变换详解
前端·css·tensorflow
__BMGT()1 小时前
C++ QT 打开图片
前端·c++·qt
仍然探索未知中2 小时前
前端扫盲HTML
前端·html
Brilliant Nemo2 小时前
Vue2项目中使用videojs播放mp4视频
开发语言·前端·javascript
酷爱码3 小时前
Linux实现临时RAM登录的方法汇总
linux·前端·javascript
LuckyLay3 小时前
Vue百日学习计划Day16-18天详细计划-Gemini版
前端·vue.js·学习