[英]Is it possible to only blur background image solely in CSS like is done in video production?
In my site, I have a photo div with random user submitted pictures.在我的站点中,我有一个带有随机用户提交图片的照片 div。 I have the same 'fill the frame' issues as landscape video like broadcast television when mixed with portrait cell phone video - they use a blurred enlarged version to fill the unused space.
当与纵向手机视频混合时,我遇到了与广播电视等横向视频相同的“填充框架”问题 - 他们使用模糊的放大版本来填充未使用的空间。 Is there a way to produce this effect solely in CSS?
有没有办法只在 CSS 中产生这种效果? In all of my attempts, the blur affects the entire stack, blurring all overlaying images and text.
在我所有的尝试中,模糊影响了整个堆栈,模糊了所有叠加的图像和文本。
<div class="h-full">
<div style=" background: url('url');background-size:cover;filter:blur(8px);">
<img class="h-[390px] w-full object-contain object-center" src="url">
</div>
</div>
Desired Outcome期望的结果
My Outcome My image is portrait and is showing twice, but totally ruined by the blur bleeding through我的结果我的图像是肖像并且显示了两次,但完全被渗入的模糊破坏了
Extra Credit: Does this effect have a official name?额外学分:这种效果有正式名称吗?
You may use backdrop-filter
to prevent edge bleeding for blurred background (click Run code snippet again to see a different picture):您可以使用
backdrop-filter
来防止模糊背景的边缘出血(再次单击运行代码片段以查看不同的图片):
body { margin: 0; overflow: hidden; }.image-frame { width: 100vw; height: 100vh; position: relative; }.image-frame.blur { position: absolute; width: 100%; height: 100%; top: 0; left: 0; background-size: cover; background-position: center; }.image-frame img { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: contain; object-position: center; /* blurring */ backdrop-filter: blur(10px); }
<div class="image-frame"> <div class="blur" style="background-image: url(https://picsum.photos/512/512)"></div> <img src="https://picsum.photos/512/512" /> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.