html - 在这个超级简单的示例中,如何模糊黑框/边框?
问题描述
我要做的就是用一个会模糊背景图像的框替换黑框。这是我的网页的过度简化版本。如果我能纠正这段代码,我就能弄清楚其余的。
这是我的示例和代码: https ://jsfiddle.net/no_u_turn/8ymc7xeb/1/
body {
background-image:url('https://i.ibb.co/DKtSK1h/background-image.jpg');
background-attachment:fixed;
background-repeat:no-repeat;
background-size:cover;
}
.top-box {
width:100%;
height:600px;
text-align:center;
padding-top:100px;
}
.blur-background-box {
width:300px;
height:300px;
background-color:black;
/*filter:blur(5px);*/
margin:0 auto;
padding-top:50px;
}
.solid-white-box {
width:200px;
height:200px;
background-color:white;
margin:0 auto;
}
.bottom-box {
width:100%;
height:1000px;
background-color:white;
}
<div class="top-box">
<div class="blur-background-box">
<div class="solid-white-box">
</div>
</div>
</div>
<div class="bottom-box">
</div>
哦,是的,我只需要在 CSS 中完成,不需要 JavaScript。基本上,我需要代码可以在所有浏览器和所有设备上工作。
我会整晚都在做这件事。欢迎任何和所有建议!提前谢谢。
解决方案
由于您正在使用background-attachment:fixed;
,因此您可以在黑匣子上应用相同的背景,您将获得所需的效果。为避免内容模糊,请使用伪元素:
body {
background-image:url('https://i.ibb.co/DKtSK1h/background-image.jpg');
background-attachment:fixed;
background-repeat:no-repeat;
background-size:cover;
}
.top-box {
width:100%;
height:600px;
text-align:center;
padding-top:100px;
}
.blur-background-box {
width:300px;
height:300px;
margin:0 auto;
padding-top:50px;
position:relative;
z-index:0;
}
.blur-background-box:before {
content:"";
position:absolute;
z-index:0;
top:0;
left:0;
bottom:0;
right:0;
background-image:url('https://i.ibb.co/DKtSK1h/background-image.jpg');
background-attachment:fixed;
background-repeat:no-repeat;
background-size:cover;
filter:blur(5px);
}
.solid-white-box {
width:200px;
height:200px;
background-color:white;
margin:0 auto;
position:relative;
z-index:1;
}
.bottom-box {
width:100%;
height:1000px;
background-color:white;
}
<div class="top-box">
<div class="blur-background-box">
<div class="solid-white-box">
</div>
</div>
</div>
<div class="bottom-box">
</div>
推荐阅读
- ruby-on-rails - `heroku run rake db:seed` 失败且没有错误;表在远程数据库中存在但为空
- java - 从 Activiti 工作流中检索所有用户任务
- pytorch - 如何找到 torch.nn.conv_transpose2d 和 max_unpool2d 的参数?
- java - docker中的内存使用超过了xmx控制或小于xms
- javascript - momentjs 不会按照指定的时区更改日期/时间
- c# - 身份确认电子邮件问题
- unity3d - Unity - 球弹跳
- java - 在 vscode 中运行 Java:“构建失败,要继续吗?” 如果我选择“继续”,它工作正常
- vue.js - 在 vuepress 中,如何将一些 md 内容动态呈现为客户主题(vue 模板)
- powershell - 如何让powershell等待批处理文件完成远程服务器上所有命令的执行