Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

背景变暗与毛玻璃效果 #122

Open
lovelmh13 opened this issue Jul 23, 2021 · 0 comments
Open

背景变暗与毛玻璃效果 #122

lovelmh13 opened this issue Jul 23, 2021 · 0 comments

Comments

@lovelmh13
Copy link
Owner

使用渐变属性让背景变暗:
linear-gradient
使用伪元素做到只让背景图有毛玻璃效果,不影响其他的元素。配合 z-index 让伪元素在下面。

html 结构如下:

image

.live-mask-container {
    z-index: 99;
    background: linear-gradient(
        rgba(0, 0, 0, 0.7),
        rgba(0, 0, 0, 0.7)
    ), url('https://pic.lehe.com/pic/_o/39/99/299009b83cb8012dcea7efdcdc8e_268_268.cz.jpg') center no-repeat;
    &:after{
      content: "";
      width:100%;
      height:100%;
      position: absolute;
      left:0;
      top:0;
      background: inherit;
      filter: blur(5px);
      z-index: -1; /* -1 是因为其他的 mask-header、mask-center 等元素没有 z-index, 所以要让 :after 变成 0 以下*/
    }
 
 
}

如果使用 opacity 修改背景图片的透明度达到使背景变暗的效果,则会与 filter 属性有一些冲突。

效果如下:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant