【问题标题】:How to make Material UI v1.0 Dialog background transparent?Material UI v1.0 如何让对话框背景透明?
【发布时间】:2018-06-03 14:40:55
【问题描述】:

我正在尝试在对话框中放置一个 CircularProgress。但是对话框背景是白色的,不能像早期版本一样设置为透明-Material UI v0.2

style={{
    width: '200px',
    marginLeft: '40%',
    backgroundColor: 'transparent'
}}

我需要使对话框背景透明。这是我的代码:

<Dialog
      bodyStyle={{margin: 0, padding: 0}}
      open={true}
      style={{
        width: '200px',
        marginLeft: '40%',
        backgroundColor: 'transparent'
      }}
      overlayStyle={{backgroundColor: 'transparent'}}
    >
      <CircularProgress
        style={{display: 'inline-block'}}
        size={50}
        color={"#00db49"}
      />
</Dialog>

如图所示如何去掉对话框中的滚动条?

【问题讨论】:

    标签: css reactjs dialog material-ui


    【解决方案1】:

    您可以使用 Dialog 组件中的 PaperProps 属性覆盖 Paper 元素 css 属性。 (来自这里:https://material-ui.com/api/dialog/

    举个例子:

        <Dialog
          onClose={this.handleClose}
          aria-labelledby="simple-dialog-title"
          {...other}
          BackdropProps={{
            classes: {
             root: classes.root
            }
           }
          }
          PaperProps ={{
            classes: {
             root: classes.paper
            }
          }}
          >
          <DialogTitle id="simple-dialog-title">Set backup 
     account
          </DialogTitle>
           // code you want is here   
        </Dialog>
    

    纸张样式应如下提供:

    const styles = {
      root: {
        backgroundColor: "transparent"
      },
    
      paper: {
        backgroundColor: "transparent",
        boxShadow: "none",
        overflow: "hidden"
      },
    };
    

    希望这会对您有所帮助,这是一个工作示例:https://codesandbox.io/s/j3wmyv7w2w

    【讨论】:

    • 如何让根背景有透明覆盖?
    【解决方案2】:

    啊.. 覆盖材料 ui css 总是一个挑战

    因为您不能使用样式和类直接覆盖 material-ui 嵌套的 div css。 因为对话框还继承了该背景覆盖的 MODAL 属性,这就是为什么您必须使用 Modal 道具中列出的道具之一,并且对于此用例,您必须覆盖 Backdrop 道具列在 Modal api 文档中。

    简单来说,只需将其写入您的对话框中

    // outside react class 
    const styles = {
      root: {
        backgroundColor: "transparent"
      }
    };
    
    // In your react class 
    <Dialog
      onClose={this.handleClose}
      aria-labelledby="simple-dialog-title"
      {...other}
      BackdropProps={{
      classes: {
        root: classes.root
        }
       }}
      >
    

    我在代码沙箱中附加了材料 ui 的工作示例。请参考下面

    确保使用 withStyles() 包装您的组件,如下例所示

    CodeSandBox 链接:https://codesandbox.io/s/5xp76wn3xp

    要隐藏滚动条,这里已经回答了这个问题:Hide scroll bar, but while still being able to scroll

    如果您需要更多帮助,请告诉我

    【讨论】:

    • 我指的是对话框中除了进度之外的滚动条。请你检查一下。 (这可以在屏幕截图中看到)
    • codesandbox示例对话框背景不透明?
    • 嗨@ShanikaEdiriweera 我无法在代码沙箱codesandbox.io/s/535w4r82jn 上复制这个场景如果你能提供链接工作链接到这个问题会很好同时,你使用一些CSS来删除滚动条在对话框上尝试一些 { min-height, overflow: hidden, } 在对话框的对话框根类
    • 是的,它在这个链接中是透明的 codesandbox.io/s/5xp76wn3xp 你看不到变化吗?
    • 我认为你没有正确理解这个问题。我想要透明的不是背景屏幕,而是对话框本身的背景。请参阅已接受的答案。感谢您的帮助。
    猜你喜欢
    • 2019-08-12
    • 1970-01-01
    • 2023-03-29
    • 2022-01-23
    • 1970-01-01
    • 2023-03-30
    • 2014-02-23
    • 2012-06-03
    • 2012-05-14
    相关资源
    最近更新 更多