如何解决背景依恋如何与它的孩子一起工作?
我一直在寻找如何使用 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 举报,一经查实,本站将立刻删除。