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>
相关推荐
你的人类朋友36 分钟前
说说git的变基
前端·git·后端
姑苏洛言39 分钟前
网页作品惊艳亮相!这个浪浪山小妖怪网站太治愈了!
前端
字节逆旅1 小时前
nvm 安装pnpm的异常解决
前端·npm
Jerry1 小时前
Compose 从 View 系统迁移
前端
GIS之路1 小时前
2025年 两院院士 增选有效候选人名单公布
前端
四岁半儿1 小时前
vue,H5车牌弹框定制键盘包括新能源车牌
前端·vue.js
烛阴2 小时前
告别繁琐的类型注解:TypeScript 类型推断完全指南
前端·javascript·typescript
gnip2 小时前
工程项目中.env 文件原理
前端·javascript
JefferyXZF2 小时前
Next.js Server Actions 详解: 无缝衔接前后端的革命性技术(八)
前端·全栈·next.js
芜青3 小时前
HTML+CSS:浮动详解
前端·css·html