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>
相关推荐
( ̄(工) ̄)霸天下20 分钟前
Typescript速通教程
前端·javascript·typescript
求知若渴,虚心若愚。4 小时前
Error reading config file (/home/ansible.cfg): ‘ACTION_WARNINGS(default) = True
linux·前端·ansible
LinDaiuuj5 小时前
最新的前端技术和趋势(2025)
前端
一只小风华~5 小时前
JavaScript 函数
开发语言·前端·javascript·ecmascript·web
程序猿阿伟6 小时前
《不只是接口:GraphQL与RESTful的本质差异》
前端·restful·graphql
若梦plus8 小时前
Nuxt.js基础与进阶
前端·vue.js
樱花开了几轉8 小时前
React中为甚么强调props的不可变性
前端·javascript·react.js
风清云淡_A8 小时前
【REACT18.x】CRA+TS+ANTD5.X实现useImperativeHandle让父组件修改子组件的数据
前端·react.js
小飞大王6668 小时前
React与Rudex的合奏
前端·react.js·前端框架
若梦plus8 小时前
React之react-dom中的dom-server与dom-client
前端·react.js