100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > css实现背景模糊效果

css实现背景模糊效果

时间:2018-07-06 09:51:47

相关推荐

css实现背景模糊效果

最近在工作中写样式的时候碰到如图这样的背景模糊效果,思来想去没有合适的方法。后查询相关资料后得出解决方案

方法:background-color + backdrop-filter 来配合实现

backdrop-filter css属性可以让你为一个元素后面区域添加图形效果(如模糊或颜色偏移)。因为它适用于元素背后的所有元素,为了看到效果,必须使元素或其背景至少部分透明。

例:

<div class="container"><div class="box"><p>backdrop-filter: blur(10px)</p></div></div>

html,body {height: 100%;width: 100%;}body {background-image: url(https://picsum.photos/id/1080/6858/4574), linear- gradient(rgb(219, 166, 166), rgb(0, 0, 172));background-position: center center;background-repeat: no-repeat;background-size: cover;}.box {/* 重点设置下面两个属性 */background-color: rgba(255, 255, 255, 0.3);backdrop-filter: blur(10px);-webkit-backdrop-filter: blur(5px);border-radius: 5px;font-family: sans-serif;text-align: center;line-height: 1;max-width: 50%;max-height: 50%;padding: 20px 40px;color: #fff;}.container {align-items: center;display: flex;justify-content: center;height: 100%;width: 100%;}

效果图:

可自行设置想要的背景色和blue数值来达到想要的模糊效果~

参考:backdrop-filter 属性介绍

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。