I have a modal that is supposed to pop up to show the status of a transaction going through on my website. It works fine other than the fact that the backdrop dimming effect is also applied on top of the modal. My modal is supposed to be white but it ends up being a sort of dark gray. I'm not sure what I'm doing wrong. Here's how it looks

这就是对情态车的期待

onst modalStyle = {
    position: 'absolute' as 'absolute',
    top: 0,
    left: 0,
    width: "80%",
    marginLeft: "auto",
    marginRight: "auto",
    marginTop: "150px",
    marginBottom: "150px",
    bgcolor: 'white',
    boxShadow: 24,
    p: 3,
    borderRadius: "25px"
}

下面是它的HTML语言:

<Modal
    open={open}
    aria-labelledby="modal-modal-title"
    aria-describedby="modal-modal-description"
    sx={modalStyle}
>
    {!done ? (
        <div style={{ display: "flex", flexDirection: "column", height: "100%", alignItems: "center" }}>
            <h1 style={{ fontSize: "50px", textAlign: "center", fontWeight: "700" }}>Transaction Loading...</h1>
            <Box style={{ display: 'flex', width: "300px", height: "300px", justifyContent: "center", }}>
                <CircularProgress style={{ marginTop: "50px" }} size={150} />
            </Box>
        </div>) : (
        <div style={{ display: "flex", flexDirection: "column", height: "100%", alignItems: "center", zIndex: "25" }}>
            <h1 style={{ fontSize: "50px", textAlign: "center", fontWeight: "700" }}>Transaction Completed!</h1>

            <svg className={styles.animatedCheck} viewBox="0 0 24 24">
                <path d="M4.1 12.7L9 17.6 20.3 6.3" fill="none" />
            </svg>
        </div>)}
</Modal>

我真的不知道哪里出了问题.这很奇怪,因为我在我的项目中的另一个地方使用了非常类似的模式声明,它完全按照预期工作.

推荐答案

Modal组件只是在背景组件前面呈现您传递给它的任何children--这取决于您对children的样式.之所以会出现这个问题,是因为在您的代码中,您正在try 设置modal根的样式,而不是它的children.

要解决此问题,请将内容包装在另一个可应用样式的元素中,然后将modalStyle样式移至该元素.在我的例子中,我将它们包装在一个Box中:

<Modal
  open={open}
  aria-labelledby="modal-modal-title"
  aria-describedby="modal-modal-description"
>
  <Box sx={modalStyle}> {/* Moved here */}
    ...
  </Box>
</Modal>

Which produced: Working screenshot

工作代码Sandbox :https://codesandbox.io/s/sad-christian-de6m9k?file=/demo.tsx

Css相关问答推荐

Tailwind CSS group-hover不适用于自定义前置码

如何在CSS中使用nextJs来指定基色?

Vue3日期 Select 器:禁用向左和向右箭头

如何在不重叠侧边栏的情况下尽可能使元素居中?

Next.js 条件样式

排除特定元素的目标元素

Bootstrap 5 - 更改列顺序时出现问题

如何在 TypeScript 文件中导入 CSS 模块?

使用 css 网格和 nth-child 交替行

全部:初始与使用 CSS 重置

具有自动调整大小的自动填充行的 CSS 网格

在固定高度的输入字段中垂直对齐文本而不显示:表格或填充?

媒体查询以错误的宽度触发

如何更改 Angular Material 上 mat-icon 的大小?

CSS过渡自动高度不起作用

输入和文本字段中的背景 colored颜色

名称-值对的语义和 struct

如何在 React 应用程序中使用 CSS 模块应用全局样式?

CSS关键帧动画CPU占用率高,应该这样吗?

如何将页脚(div)与页面底部对齐?