随着微软Fluent Design System的出现以及新的丙烯酸材料在Windows生态系统中的传播,我认为在某些Web布局中使用它会很棒。
根据the spec,丙烯酸层的成分是:
所以我开始尝试一种仅受CSS影响的方法,灵感来自该图片中的图层,这样:
body {
margin: 0;
font: 1em/1.4 Sans-serif;
background: url("https://cdn.pixabay.com/photo/2017/03/27/16/50/beach-2179624_1280.jpg") center center;
background-size: 100vw auto;
}
main {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.acrylic {
padding: 4em 6em;
position: relative;
overflow: hidden;
}
.acrylic::before {
background: url("https://cdn.pixabay.com/photo/2017/03/27/16/50/beach-2179624_1280.jpg") center center;
background-size: 100vw auto;
filter: blur(10px);
content: "";
position: absolute;
left: -10px;
top: -10px;
width: calc(100% + 20px);
height: calc(100% + 20px);
z-index: -1;
}
.acrylic::after {
content: "";
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
z-index: -1;
opacity: 0.65;
border: 1px solid #fff;
background: #fff;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAUVBMVEWFhYWDg4N3d3dtbW17e3t1dXWBgYGHh4d5eXlzc3OLi4ubm5uVlZWPj4+NjY19fX2JiYl/f39ra2uRkZGZmZlpaWmXl5dvb29xcXGTk5NnZ2c8TV1mAAAAG3RSTlNAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEAvEOwtAAAFVklEQVR4XpWWB67c2BUFb3g557T/hRo9/WUMZHlgr4Bg8Z4qQgQJlHI4A8SzFVrapvmTF9O7dmYRFZ60YiBhJRCgh1FYhiLAmdvX0CzTOpNE77ME0Zty/nWWzchDtiqrmQDeuv3powQ5ta2eN0FY0InkqDD73lT9c9lEzwUNqgFHs9VQce3TVClFCQrSTfOiYkVJQBmpbq2L6iZavPnAPcoU0dSw0SUTqz/GtrGuXfbyyBniKykOWQWGqwwMA7QiYAxi+IlPdqo+hYHnUt5ZPfnsHJyNiDtnpJyayNBkF6cWo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ULOa4MP+W/HfGadZUbfw177G7j/OGbIs8TahLyynl4X4RinF793Oz+BU0saXtUHrVBFT/DnA3ctNPoGbs4hRIjTok8i+algT1lTHi4SxFvONKNrgQFAq2/gFnWMXgwffgYMJpiKYkmW3tTg3ZQ9Jq+f8XN+A5eeUKHWvJWJ2sgJ1Sop+wwhqFVijqWaJhwtD8MNlSBeWNNWTa5Z5kPZw5+LbVT99wqTdx29lMUH4OIG/D86ruKEauBjvH5xy6um/Sfj7ei6UUVk4AIl3MyD4MSSTOFgSwsH/QJWaQ5as7ZcmgBZkzjjU1UrQ74ci1gWBCSGHtuV1H2mhSnO3Wp/3fEV5a+4wz//6qy8JxjZsmxxy5+4w9CDNJY09T072iKG0EnOS0arEYgXqYnXcYHwjTtUNAcMelOd4xpkoqiTYICWFq0JSiPfPDQdnt+4/wuqcXY47QILbgAAAABJRU5ErkJggg==);
}
.shadow {
border-radius: 1px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1), 0 1px 8px rgba(0, 0, 0, 0.2);
}

<main>
<div class="acrylic shadow">
Acrylic material!
</div>
</main>
&#13;
结果非常接近规范并且也有响应,但是有一个很大的问题:只是堆叠另一个.acrylic
div并且背景技巧不再起作用。
问题是: 是否有更智能的高斯模糊方法,而不会为每个孩子重复身体背景?或者也许是一些更聪明的方法来计算其位置?
答案 0 :(得分:21)
有两种方法可以做到这一点......
.acrylic
上的模糊bg
复杂的实现,但在大多数现代浏览器上运行。backdrop-filter
.acrylic
实现非常简单,但缺乏浏览器支持。
醇>
.acrylic
我们也需要在.acrylic
家伙上复制bg,因为只是降低不透明度会显示其背后的内容而不是它们,AFAIK不会被模糊滤镜覆盖......
计算位置的智能方法是为父元素(background-attachment: fixed
)和body
两者设置.acrylic
,这样您就可以拥有多个.acrylic
个人好吧;)
由于我们对父母和孩子使用相同的背景,我们可以将他们聚在一起;)
body, .acrylic::before {
background: url("IMG_URL_HERE") center/cover;
background-attachment: fixed;
}
这是一个工作片段;)
将.acrylic:after
的不透明度降低了一点,因此背景更加明显;)
body {
margin: 0;
font: 1em/1.4 Sans-serif;
}
body, .acrylic::before {
background: url("https://images.unsplash.com/photo-1452723312111-3a7d0db0e024?w=700") center/cover;
background-attachment: fixed;
}
main {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.acrylic {
padding: 4em 6em;
position: relative;
overflow: hidden;
margin: 1em;
}
.acrylic::before {
filter: blur(10px);
content: "";
position: absolute;
left: -10px;
top: -10px;
width: calc(100% + 20px);
height: calc(100% + 20px);
z-index: -1;
}
.acrylic::after {
content: "";
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
z-index: -1;
opacity: 0.35;
border: 1px solid #fff;
background: #fff;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAUVBMVEWFhYWDg4N3d3dtbW17e3t1dXWBgYGHh4d5eXlzc3OLi4ubm5uVlZWPj4+NjY19fX2JiYl/f39ra2uRkZGZmZlpaWmXl5dvb29xcXGTk5NnZ2c8TV1mAAAAG3RSTlNAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEAvEOwtAAAFVklEQVR4XpWWB67c2BUFb3g557T/hRo9/WUMZHlgr4Bg8Z4qQgQJlHI4A8SzFVrapvmTF9O7dmYRFZ60YiBhJRCgh1FYhiLAmdvX0CzTOpNE77ME0Zty/nWWzchDtiqrmQDeuv3powQ5ta2eN0FY0InkqDD73lT9c9lEzwUNqgFHs9VQce3TVClFCQrSTfOiYkVJQBmpbq2L6iZavPnAPcoU0dSw0SUTqz/GtrGuXfbyyBniKykOWQWGqwwMA7QiYAxi+IlPdqo+hYHnUt5ZPfnsHJyNiDtnpJyayNBkF6cWoYGAMY92U2hXHF/C1M8uP/ZtYdiuj26UdAdQQSXQErwSOMzt/XWRWAz5GuSBIkwG1H3FabJ2OsUOUhGC6tK4EMtJO0ttC6IBD3kM0ve0tJwMdSfjZo+EEISaeTr9P3wYrGjXqyC1krcKdhMpxEnt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+A5eeUKHWvJWJ2sgJ1Sop+wwhqFVijqWaJhwtD8MNlSBeWNNWTa5Z5kPZw5+LbVT99wqTdx29lMUH4OIG/D86ruKEauBjvH5xy6um/Sfj7ei6UUVk4AIl3MyD4MSSTOFgSwsH/QJWaQ5as7ZcmgBZkzjjU1UrQ74ci1gWBCSGHtuV1H2mhSnO3Wp/3fEV5a+4wz//6qy8JxjZsmxxy5+4w9CDNJY09T072iKG0EnOS0arEYgXqYnXcYHwjTtUNAcMelOd4xpkoqiTYICWFq0JSiPfPDQdnt+4/wuqcXY47QILbgAAAABJRU5ErkJggg==);
}
.shadow {
border-radius: 1px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1), 0 1px 8px rgba(0, 0, 0, 0.2);
}
&#13;
<main>
<div class="acrylic shadow">
Acrylic material!
</div>
<div class="acrylic shadow">
Acrylic material!
</div>
</main>
<main>
<div class="acrylic shadow">
Acrylic material!
</div>
<div class="acrylic shadow">
Acrylic material!
</div>
</main>
<main>
<div class="acrylic shadow">
Acrylic material!
</div>
</main>
&#13;
backdrop-filter
.acrylic
&#13;
main {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.acrylic {
padding: 4em 6em;
position: relative;
background: rgba(0,0,0,0.5);
-webkit-backdrop-filter: blur(10px);
backdrop-filter: blur(10px);
margin: 7px;
}
body {
background: url("https://images.unsplash.com/photo-1452723312111-3a7d0db0e024?w=700") center/cover;
background-attachment: fixed;
margin: 0;
font: 1em/1.4 Sans-serif;
color: #fff;
}
&#13;
答案 1 :(得分:11)
我认为你遇到的唯一问题是应用于:: before的背景对齐和正文是不同的。因此,通过将CSS组合成一个,我已经将其缩短,以便更新和编辑它。
我使用 background:rgba()而不是#hex值来提供不透明度控件的更大灵活性。
我在整个CSS中添加了注释来解释我为使它们更明显所做的更改。
注意:从类后删除不透明度会导致透明度增加并增加噪声纹理的可见性。我相信它是由噪声纹理本身半透明引起的,但这是一种奇怪的行为,如果有其他人知道并且有更好的解释我会有兴趣知道。我添加了.nested和.parent类。因为最好分别控制这些东西。我在第二个例子中删除了.parent,在第三个例子中删除了。
更新:注意到未包含规范中提到的排除混合过滤器,所以我也添加了它。在摘录下面提供了来源。
希望这有帮助。 :)
/* Adding the background source for
both elements together simplifies editing.
Changing the background color #333 to #fff
will produce much more intence effect on
the filter blend */
html,
.acrylic:before {
background: #333 url(https://source.unsplash.com/1600x900/?nature) 50% 100% fixed;
background-size: cover;
}
body {
margin: 0;
font: 1em/1.4 Sans-serif;
}
/*div spacings*/
div {
margin: 5px;
}
main {
display: flex;
align-items: center;
justify-content: center;
flex-flow: row wrap;
height: 100vh;
}
.acrylic {
padding: 4em 6em;
position: relative;
overflow: hidden;
}
/*Added browser compatibility for blurring added the exclusion blend filter as explained in the original document*/
.acrylic::before {
content: '';
position: absolute;
z-index: -1;
height: 100%;
top: 0;
right: 0;
left: 0;
filter: blur(8px);
-webkit-filter: blur(8px);
-moz-filter: blur(8px);
-o-filter: blur(8px);
-ms-filter: blur(8px);
background-blend-mode: exclusion;
}
/*made color rgba removed opacity property*/
.acrylic::after {
content: "";
position: absolute;
height: 100%;
left: 0;
top: 0;
right: 0;
bottom: 0;
z-index: -1;
border: 1px solid #fff;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAUVBMVEWFhYWDg4N3d3dtbW17e3t1dXWBgYGHh4d5eXlzc3OLi4ubm5uVlZWPj4+NjY19fX2JiYl/f39ra2uRkZGZmZlpaWmXl5dvb29xcXGTk5NnZ2c8TV1mAAAAG3RSTlNAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEAvEOwtAAAFVklEQVR4XpWWB67c2BUFb3g557T/hRo9/WUMZHlgr4Bg8Z4qQgQJlHI4A8SzFVrapvmTF9O7dmYRFZ60YiBhJRCgh1FYhiLAmdvX0CzTOpNE77ME0Zty/nWWzchDtiqrmQDeuv3powQ5ta2eN0FY0InkqDD73lT9c9lEzwUNqgFHs9VQce3TV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1Y9p+tktDYYSNflcxI0iyO4TPBdlRcpeqjK/piF5bklq77VSEaA+z8qmJTFzIWiitbnzR794USKBUaT0NTEsVjZqLaFVqJoPN9ODG70IPbfBHKK+/q/AWR0tJzYHRULOa4MP+W/HfGadZUbfw177G7j/OGbIs8TahLyynl4X4RinF793Oz+BU0saXtUHrVBFT/DnA3ctNPoGbs4hRIjTok8i+algT1lTHi4SxFvONKNrgQFAq2/gFnWMXgwffgYMJpiKYkmW3tTg3ZQ9Jq+f8XN+A5eeUKHWvJWJ2sgJ1Sop+wwhqFVijqWaJhwtD8MNlSBeWNNWTa5Z5kPZw5+LbVT99wqTdx29lMUH4OIG/D86ruKEauBjvH5xy6um/Sfj7ei6UUVk4AIl3MyD4MSSTOFgSwsH/QJWaQ5as7ZcmgBZkzjjU1UrQ74ci1gWBCSGHtuV1H2mhSnO3Wp/3fEV5a+4wz//6qy8JxjZsmxxy5+4w9CDNJY09T072iKG0EnOS0arEYgXqYnXcYHwjTtUNAcMelOd4xpkoqiTYICWFq0JSiPfPDQdnt+4/wuqcXY47QILbgAAAABJRU5ErkJggg==);
}
/*Individual control over
.nested and .parent opacity and color.*/
.parent::after {
background-color: rgba(230, 240, 255, 0.50);
opacity: 0.60;
}
.child::after {
background-color: rgba(230, 240, 255, 0.30);
opacity: 0.60;
}
.shadow {
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2), 0 1px 8px rgba(0, 0, 0, 0.4);
}
<body>
<main>
<div class="acrylic shadow parent">
<div class="acrylic child">
Acrylic material! <br />.parent on .child on
</div>
</div>
<div class="acrylic shadow">
<div class="acrylic child">
Acrylic material! <br />.parent off .child on
</div>
</div>
<div class="acrylic shadow">
<div class="acrylic">
Acrylic material! <br />.parent off .child off
</div>
</div>
</main>
</body>
您可以在CSS Tricks here.
上找到前玻璃效果的来源复制图像技术需要保持模糊图像 与原始一起,如果你需要重用,这可能会变得很痛苦 多个图像的效果。例如,响应式设计可能 需要在不同的屏幕尺寸下交换不同的图像。要么, 模板布局可能会动态地丢失图像(例如,不同的 每篇博文的标题图片)。对于这些情况,它会很好 仅使用源图像生成效果。毕竟,我们是 只是模糊了它。
他们还说,如果你想提供更多的浏览器支持,你可以添加SVG过滤器作为后备,虽然我没有将它添加到我自己的代码片段中,但他们这样说:
CSS过滤器有点新鲜。这意味着他们可能是供应商前缀, 他们的浏览器支持尚未普及。但是,过滤器 在SVG中有更长的历史记录,并将SVG过滤器应用于HTML内容 通过CSS有更广泛的浏览器支持。您可以轻松地将它们添加为 不支持CSS过滤器时的后备。上面的演示 实际上就是这样。
要添加SVG过滤器,我们在HTML标记中包含一些内联SVG, 并使用url()引用过滤器。专业提示:另一种选择是 将SVG过滤器和引用编码为数据URL,但格式为 在文章中阅读起来有点困难。
并提供了一个代码示例
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<filter id="blur">
<feGaussianBlur stdDeviation="5" />
</filter>
</defs>
</svg>
.glass::before {
background-image: url('pelican.jpg');
/* Fallback to SVG filters */
filter: url('#blur');
filter: blur(5px);
}
有关CSS滤镜混合的更多信息,请转到此处 https://css-tricks.com/basics-css-blend-modes
答案 2 :(得分:2)
自7月29日起,backdrop-filter
CSS功能终于有了shipped in Chrome 76。不幸的是,Firefox expected to be delivered in a Q3 2019 release仍在使用它。但是,至少对于渐进式增强用例而言,至少现在显然是最佳选择。
所以,我认为最好的答案可能很简单:
/* Now all the acrylic layer is just only one class! */
.acrylic {
/* Parent background + Gaussian blur */
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
/* Exclusion blend */
background-blend-mode: exclusion;
/* Color/tint overlay + Opacity */
background: rgba(255, 255, 255, .6);
/* Tiled noise texture */
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAUVBMVEWFhYWDg4N3d3dtbW17e3t1dXWBgYGHh4d5eXlzc3OLi4ubm5uVlZWPj4+NjY19fX2JiYl/f39ra2uRkZGZmZlpaWmXl5dvb29xcXGT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5yAg3AL1fm8T9AZtp/bbJGwl1pNrE7RuOX7PeMRUERVaPpEs+yqeoSmuOlokqw49pgomjLeh7icHNlG19yjs6XXOMedYm5xH2YxpV2tc0Ro2jJfxC50ApuxGob7lMsxfTbeUv07TyYxpeLucEH1gNd4IKH2LAg5TdVhlCafZvpskfncCfx8pOhJzd76bJWeYFnFciwcYfubRc12Ip/ppIhA1/mSZ/RxjFDrJC5xifFjJpY2Xl5zXdguFqYyTR1zSp1Y9p+tktDYYSNflcxI0iyO4TPBdlRcpeqjK/piF5bklq77VSEaA+z8qmJTFzIWiitbnzR794USKBUaT0NTEsVjZqLaFVqJoPN9ODG70IPbfBHKK+/q/AWR0tJzYHRULOa4MP+W/HfGadZUbfw177G7j/OGbIs8TahLyynl4X4RinF793Oz+BU0saXtUHrVBFT/DnA3ctNPoGbs4hRIjTok8i+algT1lTHi4SxFvONKNrgQFAq2/gFnWMXgwffgYMJpiKYkmW3tTg3ZQ9Jq+f8XN+A5eeUKHWvJWJ2sgJ1Sop+wwhqFVijqWaJhwtD8MNlSBeWNNWTa5Z5kPZw5+LbVT99wqTdx29lMUH4OIG/D86ruKEauBjvH5xy6um/Sfj7ei6UUVk4AIl3MyD4MSSTOFgSwsH/QJWaQ5as7ZcmgBZkzjjU1UrQ74ci1gWBCSGHtuV1H2mhSnO3Wp/3fEV5a+4wz//6qy8JxjZsmxxy5+4w9CDNJY09T072iKG0EnOS0arEYgXqYnXcYHwjTtUNAcMelOd4xpkoqiTYICWFq0JSiPfPDQdnt+4/wuqcXY47QILbgAAAABJRU5ErkJggg==);
/* Some unrelated styling... */
padding: 1.5em;
border-radius: 1px;
border: 1px solid rgba(255, 255, 255, .2);
box-shadow: 0 10px 30px rgba(0, 0, 0, .1), 0 1px 8px rgba(0, 0, 0, .2);
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
/* Body and main styles... */
body {
margin: 0;
padding: 1.5em;
font: 1em/1.4 Sans-serif;
/* Now our background image is defined only in the body! */
background: url("https://cdn.pixabay.com/photo/2017/03/27/16/50/beach-2179624_1280.jpg") center center;
background-size: 100vw auto;
}
main {
display: grid;
gap: 1.5rem;
justify-content: center;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
grid-auto-rows: minmax(120px, auto);
}
<main>
<div class="acrylic">
Acrylic material!
</div>
<div class="acrylic">
<div class="acrylic">
Acrylic inside acrylic!
</div>
</div>
<div class="acrylic">
Acrylic material!
</div>
<div class="acrylic">
Acrylic material!
</div>
</main>
答案 3 :(得分:0)
是否有一些更聪明的方法来高斯模糊而不重复 每个孩子的身体背景?
据我所知,在这种情况下没有更明智的方法来实现这一点,因为必须将background image
和filter
设置为相同的div以创建所需的效果。
或者可能有一些更聪明的方法来动态计算它的位置?
据我所知,问题在于每增加一个div .acrylic
,图像的背景部分就会重复。
由于您使用相同的背景图片,因此只需将background-attachment: fixed
添加到div .acrylic::before
即可解决此问题。
body {
margin: 0;
font: 1em/1.4 Sans-serif;
background: url("http://www.wallpapers-web.com/data/out/191/5484624-sunset-wallpapers.jpg") center center;
background-size: 100vw auto;
}
main {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.acrylic {
padding: 4em 6em;
position: relative;
overflow: hidden;
}
.acrylic::before {
background: url("http://www.wallpapers-web.com/data/out/191/5484624-sunset-wallpapers.jpg") center center;
background-size: 100vw auto;
background-attachment: fixed;
filter: blur(10px);
content: "";
position: absolute;
left: -10px;
top: -10px;
width: calc(100% + 20px);
height: calc(100% + 20px);
z-index: -1;
}
.acrylic::after {
content: "";
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
z-index: -1;
opacity: 0.65;
border: 1px solid #fff;
background: #fff;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAUVBMVEWFhYWDg4N3d3dtbW17e3t1dXWBgYGHh4d5eXlzc3OLi4ubm5uVlZWPj4+NjY19fX2JiYl/f39ra2uRkZGZmZlpaWmXl5dvb29xcXGTk5NnZ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AL1fm8T9AZtp/bbJGwl1pNrE7RuOX7PeMRUERVaPpEs+yqeoSmuOlokqw49pgomjLeh7icHNlG19yjs6XXOMedYm5xH2YxpV2tc0Ro2jJfxC50ApuxGob7lMsxfTbeUv07TyYxpeLucEH1gNd4IKH2LAg5TdVhlCafZvpskfncCfx8pOhJzd76bJWeYFnFciwcYfubRc12Ip/ppIhA1/mSZ/RxjFDrJC5xifFjJpY2Xl5zXdguFqYyTR1zSp1Y9p+tktDYYSNflcxI0iyO4TPBdlRcpeqjK/piF5bklq77VSEaA+z8qmJTFzIWiitbnzR794USKBUaT0NTEsVjZqLaFVqJoPN9ODG70IPbfBHKK+/q/AWR0tJzYHRULOa4MP+W/HfGadZUbfw177G7j/OGbIs8TahLyynl4X4RinF793Oz+BU0saXtUHrVBFT/DnA3ctNPoGbs4hRIjTok8i+algT1lTHi4SxFvONKNrgQFAq2/gFnWMXgwffgYMJpiKYkmW3tTg3ZQ9Jq+f8XN+A5eeUKHWvJWJ2sgJ1Sop+wwhqFVijqWaJhwtD8MNlSBeWNNWTa5Z5kPZw5+LbVT99wqTdx29lMUH4OIG/D86ruKEauBjvH5xy6um/Sfj7ei6UUVk4AIl3MyD4MSSTOFgSwsH/QJWaQ5as7ZcmgBZkzjjU1UrQ74ci1gWBCSGHtuV1H2mhSnO3Wp/3fEV5a+4wz//6qy8JxjZsmxxy5+4w9CDNJY09T072iKG0EnOS0arEYgXqYnXcYHwjTtUNAcMelOd4xpkoqiTYICWFq0JSiPfPDQdnt+4/wuqcXY47QILbgAAAABJRU5ErkJggg==);
}
.shadow {
border-radius: 1px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1), 0 1px 8px rgba(0, 0, 0, 0.2);
}
&#13;
<main>
<div class="acrylic shadow">Acrylic material!</div>
<div class="acrylic shadow">Acrylic material!</div>
<div class="acrylic shadow">Acrylic material!</div>
</main>
&#13;