CSS模态显示背景内容,使可读性较低
目前,我正在单击按钮中显示模态。
但问题是它也在模态部分中显示背景内容。
所以,我的模态内容文本与主要内容相矛盾。
有人可以帮我解决这个问题吗?以下是下图中模态的代码和当前视图
.order-view-modal {
display: block;
opacity: 0.8 !important;
background-color: black;
position: fixed;
z-index: 10001 !important;
left: 0;
top: 0;
width: 100%;
height: 100%;
padding: 1rem;
}
.order-view-modal-content {
background-color: white;
width: 50%;
height: 50%;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
padding: 1rem;
}
As currently i am showing modal in react on click of button.
but problem is it is showing background content in modal portion also.
so, my modal content texts are conflicted with main content.
can someone please help me to solve this issue ? below is the code and current view of modal in below image
.order-view-modal {
display: block;
opacity: 0.8 !important;
background-color: black;
position: fixed;
z-index: 10001 !important;
left: 0;
top: 0;
width: 100%;
height: 100%;
padding: 1rem;
}
.order-view-modal-content {
background-color: white;
width: 50%;
height: 50%;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
padding: 1rem;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
之所以发生这种情况,是因为您已经添加了
不透明度:0.8!重要
样式为.erder-view-modal
。您正在降低order-view-modal
元素的不透明度,并假设order-view-view-view-modal-content
是其孩子,该样式也将应用于它。您可以做的是在
order-view-mododal
中创建另一个元素,该元素充当背景,并在其中添加不透明度样式。这样,不透明度样式将不适用于order-view-view-modal-content
。查看下面的片段。过渡的解决方案:
添加过渡,使用
active> active> active
的类,如下面的摘要中,以控制模态状态。单击按钮,活动
类添加到模式的类列表中。默认的垂直位置为-100%
,而活动位置为0%
。我将过渡时机添加为3s。如果感觉很长,您可以随身携带它并找到最佳位置。我还添加了
盒子大小:border-box
订单 - 视图 - 模式-BG
,以使元素高度中的填充物包含。This is happening because you've added the
opacity: 0.8 !important
style to.order-view-modal
. You're reducing the opacity of theorder-view-modal
element, and assumingorder-view-modal-content
is its child, that style gets applied to it as well.What you could do is create another element inside
order-view-modal
that acts as the background, and add the opacity style to that. This way the opacity style will not apply toorder-view-modal-content
. Check out the snippet below.Solution for transition:
To add your transition, use a class like
active
as in the snippet below to control the state of the modal. On click of the button, theactive
class is added to the modal's classlist. The default vertical position is-100%
and the active position is0%
. I've added the transition timing as 3s. If it feels long you can play around with it and find the sweet spot.I've also added
box-sizing: border-box
toorder-view-modal-bg
in order to make the padding included in the height of the element.请考虑此解决方案。您需要在不透明的覆盖背景周围创建一个包装器,并且需要将实际型号保留在外部覆盖包装纸外部。
Please consider this solution. You need to create one more wrapper around your opaque overlay background and need to keep actual model outside overlay wrapper.