0

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

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, 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 不兼容

谢谢大家,对我糟糕的英语感到抱歉

4

0 回答 0