【问题标题】:How to change icon size on Alert in Material UI for React如何在 React 的 Material UI 中更改警报上的图标大小
【发布时间】:2020-05-11 19:09:00
【问题描述】:

最近 Material UI 开发了“警报”组件。

一切都很好,除了我看不到改变图标大小的方法。

这是我的代码:

<Snackbar open={true}>
  <Alert
    className={classes.cookieAlert}
    severity="info"
    action={<Button color="inherit" size="small">OK</Button>}
  >
    We use cookies to ensure you the best experience on our website.
  </Alert>
</Snackbar>

图标是由“严重性”定义的,我该如何更改它的大小?我不想覆盖图标,只需将其大小更改为更大。

【问题讨论】:

  • 你为什么要删除你的帖子 Matt Oestreich?您开始一团糟,然后将其删除。

标签: javascript reactjs material-ui react-material


【解决方案1】:

图标的大小由字体大小控制。下面是一个基于您的代码的示例,它显示了一种自定义方式。

import React from "react";
import Snackbar from "@material-ui/core/Snackbar";
import Button from "@material-ui/core/Button";
import Alert from "@material-ui/lab/Alert";
import { makeStyles } from "@material-ui/core/styles";

const useStyles = makeStyles({
  cookieAlert: {
    "& .MuiAlert-icon": {
      fontSize: 40
    }
  }
});

export default function App() {
  const classes = useStyles();
  return (
    <Snackbar open={true}>
      <Alert
        className={classes.cookieAlert}
        severity="info"
        action={
          <Button color="inherit" size="small">
            OK
          </Button>
        }
      >
        We use cookies to ensure you the best experience on our website.
      </Alert>
    </Snackbar>
  );
}

参考资料:

【讨论】:

    猜你喜欢
    • 2021-01-20
    • 2021-06-08
    • 2019-03-29
    • 2016-08-02
    • 2021-04-18
    • 2020-02-06
    • 2020-10-21
    • 1970-01-01
    • 2017-03-12
    相关资源
    最近更新 更多