javascript - 如何使引导模式背景获得模糊效果
问题描述
我想弄清楚使开放模态表单的背景具有模糊效果的最佳方法是什么。
我尝试过使用以下 CSS 代码:
`body.modal-open >:not(.modal) {
-webkit-filter: blur(5px) grayscale(90%);
filter: blur(5px) grayscale(90%);
}`
但它最终将它应用于包括内容在内的整个模式,我对如何实现这种效果没有任何想法。
这是触发模式的代码,我一直在尝试应用 CSS 样式。
`
<button
type="button"
id="modal"
className="btn btn-primary"
data-toggle="modal"
data-target="#exampleModalCenter">
Agendar una Cita
</button>
<div
className="modal fade"
id="exampleModalCenter"
tabIndex="-1"
role="dialog"
aria-labelledby="exampleModalCenterTitle"
aria-hidden="true">
`
该项目最初是使用 create-react-app 和 Bootstrap 框架建立的。
这是模式打开时的实际外观,但是,我希望它具有模糊的背景。
模态:
解决方案
请记住,如果您模糊一个元素,那么它也会模糊该元素以及所有子元素。所以你需要做的就是将两个元素放在彼此的顶部,然后模糊后面的那个。
例子。
这是本质:
CSS
.BLURRED-BOX {
background: blue;
color: white;
-webkit-filter: blur(5px) grayscale(90%);
filter: blur(5px) grayscale(90%);
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
display: block;
z-index: 90;
}
.NOT-BLURRED-BOX {
position: absolute;
left: 0;
right: 0;
top: 0;
z-index: 100;
width: 300px;
height: 100%;
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 100px;
}
.NOT-BLURRED-BOX img {
max-width: 100%;
height: auto;
}
(重要的)HTML
这就是模态内部的内容。
<div class="modal-body">
<div class="BLURRED-BOX">
<p>I am a blurred box</p>
<img src="https://via.placeholder.com/500" />
</div>
<div class="NOT-BLURRED-BOX">
<p>I am a not blurred box</p>
<img src="https://media0.giphy.com/media/1lI97corSEnZu/giphy.gif?cid=3640f6095c5748f668686b6a497d5f5d" />
</div>
</div>
推荐阅读
- cmake - 如何将 `include-what-you-use` 警告视为 `cmake` 的错误
- c# - App.Config 中的自定义部分,ConfigurationManager 停止工作
- c++ - G++ 4.9.2 和 8.2.0 - 最终二进制文件的依赖项,默认 lib 路径搜索 ./../lib 目录(隐式 RPATH 问题)
- java - 如何使用包含 java 文件的 jar 文件?
- php - 根据用户的角色将用户重定向到视图
- css - 如何让这个 flex 孙子显示滚动条?
- ruby-on-rails - Ruby on Rails:使用私有仓库(Yarn 包)并使用 Chef Server 进行部署
- javascript - 带有 v-for 的 Vue 动态表单字段
- ios - 如何在 SwiftUI 中更新文本标签?
- vue.js - 将 b-icon 传递给 VueJS 中的元素