【问题标题】:Im having trouble overriding material-ui root style for DialogActions我无法覆盖 DialogActions 的 material-ui 根样式
【发布时间】:2020-11-20 21:56:38
【问题描述】:

我在 DialogActions like so. 中有两个按钮

我拥有的 JSX 如下:

<DialogActions classes={{ root: classes.dialogActionsLeft }}>
  <Button
    autoFocus
    onClick={() => {
      setOpen(false);
    }}
  >
    Cancel
  </Button>
  <Button
    onClick={() => {
      setOpen(false);
      navigate("/");
    }}
  >
    Finish
  </Button>
</DialogActions>

我拥有的 CSS 是:

const useStyles = makeStyles((theme) => ({
  dialogActionsLeft: {
    "&:nth-child(1)": {
      justifyContent: `flex-start`
    }
  }
}));

如果伪选择器不存在,则两个按钮都将左对齐,如果存在,则两个按钮都保持右对齐。这告诉我我使用的伪选择器错误,但我不知道如何修复它

【问题讨论】:

    标签: css reactjs material-ui


    【解决方案1】:

    是否需要左对齐两个按钮? 如果是这种情况,请尝试&amp;:nth-child(n)

    更新

    您还必须为 dialogActionsLeft 指定 justifyContent。

    dialogActionsLeft: { justifyContent: 'space-between', '&:nth-child(1)': { justifyContent: flex-start, } }
    

    【讨论】:

    • 不,我需要第一个按钮左对齐,第二个按钮右对齐。
    • 您还必须为 dialogActionsLeft 指定 justifyContent。 ` dialogActionsLeft: { justifyContent: 'space-between', '&:nth-child(1)': { justifyContent: flex-start, } }`
    • 很高兴听到这个消息。我已经编辑了我的答案。如果可以,请接受它作为答案。如果没有,不用担心。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-30
    • 2019-03-07
    • 2020-05-27
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 2020-08-10
    相关资源
    最近更新 更多