【发布时间】:2020-11-26 02:52:41
【问题描述】:
我有一个 Material UI 全屏对话框组件,但我需要它有z-index = 7。从我的浏览器元素检查器我有这个:
你可以看到它的z-index = 1300。这是Dialog的代码:
return (
<Dialog fullScreen open onClose={handleClose} TransitionComponent={Transition}>
<AppBar className={classes.appBar} classes={{ root: classes.backColor }}>
<Toolbar>
<Typography variant="h6" className={classes.title}>
Dialog Title
</Typography>
<Button autoFocus variant="contained" color="primary" onClick={handleClose}>Close</Button>
</Toolbar>
<Paper className={classes.root} style={{ margin: '10px' }} elevation={3}>
Here I have the dialog content
</Paper>
</AppBar>
</Dialog>
);
以上代码来自https://material-ui.com/components/dialogs/全屏对话框部分。
我正在尝试的解决方案来自这里:https://material-ui.com/customization/components/#overriding-styles-with-global-class-names
这是:
const StyledDialog = withStyles({
root: {
position: 'fixed',
zIndex: 7,
right: '0px',
bottom: '0px',
top: '0px',
left: '0px'
}
})(Dialog);
...
return (
<StyledDialog fullScreen open onClose={handleClose} TransitionComponent={Transition}>
...
</StyledDialog>
)
但结果保持不变:z-index = 1300。然后我尝试了另一个来自https://material-ui.com/customization/components/#overriding-with-inline-styles:
<Dialog fullScreen open onClose={handleClose} TransitionComponent={Transition} style={{
position: 'fixed',
zIndex: 7,
right: '0px',
bottom: '0px',
top: '0px',
left: '0px'
}}>
...
</Dialog>
并没有什么新鲜事。我需要将此 Dialog z-Index 从 1300 更改为 7,但我不知道该怎么做。我在这里错过了什么?
【问题讨论】:
标签: reactjs dialog material-ui z-index