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>
相关推荐
阿山同学.9 分钟前
AWS 亚马逊 S3存储桶直传 前端demo 复制即可使用
前端·javascript·aws
Jolyne_18 分钟前
grid 实现完美的水平铺满、间隔一致的自适应布局
前端·css
西洼工作室22 分钟前
【解决导航栏字体图标渲染导致文本闪烁问题】采用腾讯视频的解决方案
前端·css·css3
WindrunnerMax29 分钟前
从零实现富文本编辑器#5-编辑器选区模型的状态结构表达
前端·架构·github
CodeSheep35 分钟前
宇树科技,改名了!
前端·后端·程序员
Hilaku42 分钟前
为什么我们用了 Vite 还是构建慢?——真正的优化在这几步
前端·javascript·vite
XI锐真的烦43 分钟前
横向对比npm和yarn
前端·npm·node.js
国家不保护废物43 分钟前
🧩 React 组件化进阶:像乐高大师一样搭建你的应用世界!
前端·react.js·ai编程
TimelessHaze1 小时前
从"切图崽"到前端工程师:React 到底是个啥?🚀
前端·react.js·ai编程
站在风口的猪11081 小时前
《前端面试题:CSS的display属性》
前端·css·html·css3·html5