背景依恋如何与它的孩子一起工作?

问题描述

我一直在寻找如何使用 CSS3 生成新的玻璃态射效果。幸运的是我找到了 This article that make it happens。在第一种方法中,文章做了这样的事情(我用相同的结构和属性编写了这段代码):

body {
    min-height: 100vh;
    background: url(./bg.jpg) no-repeat; /*<------ check that I'm using a background image*/
    background-size: cover;
    display: flex;
    align-items: center;
    justify-content: center;
    background-attachment: fixed; /*<------ This is the most important part*/
}

.contenedor {
    width: 500px;
    border-radius: 10px;
    height: 400px;
    border: 1px solid #eee;
    position: relative;
    overflow: hidden;
    background: inherit; /*<------- Here the ".contenedor" element inherits its parent's background*/
  z-index: 2;
}
.contenedor::before {
  z-index: -1;
    content: "";
    background: inherit;
    position: absolute;
    width: 100%;
    height: 100%;
    Box-shadow: inset 0px 0px 2000px rgba(255,255,0.5); /*<------- Here the magic happens making a blur inside */
    filter: blur(10px);
}

使用此 HTML:

<body>
  <div class="contenedor">
    TEXT INSIDE
  </div>
</body>

现在,我不明白 background-attachment 如何使用 .contenedor 背景维持 inherit 元素中的背景。

我知道 background:inherit 是从其父级继承所有背景属性,但是如果我放了会发生什么

{
    ...
    background: url(./bg.jpg) no-repeat; /*<------ check that I'm using a background image*/
    background-size: cover;
    background-attachment: fixed; /*<------ This is the most important part*/
    ...
}

而不是inherit,它不起作用。 PDT:当然我理解 ::before 伪类来实现背景,我使用第一种方法而不是第二种方法,因为与 Mozilla Firefox 不兼容

谢谢大家,抱歉我的英语不好

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)