【问题标题】:Change the size of the icon更改图标的大小
【发布时间】:2021-12-24 15:57:07
【问题描述】:

我有这个项目,我想做一个侧边栏,侧边栏里面有图标和一个表达这个图标的词,问题是当我想在“useStyles()”中改变图标的​​大小时它没有改变它的大小,我不知道为什么。

我该如何解决这个问题?

const useStyles = makeStyles((theme) => ({
  item: {
    display: "flex",
    alignItems: "center",
    marginBottom: theme.spacing(4),
    [theme.breakpoints.up("sm")]: {
      marginBottom: theme.spacing(3),
      cursor: "pointer",
    },
  },
  icon: {
      marginRight: theme.spacing(1),
      [theme.breakpoints.up("sm")]:{
          fontSize: "18px"
      }
  },
  text: {
      fontWeight: 500,
    [theme.breakpoints.down("sm")]: {
      display: "none",
    },
  },
  container: {
    height: "100vh",
    paddingTop: theme.spacing(2),
    color: "white",
    backgroundColor: theme.palette.primary.main,
    [theme.breakpoints.up("sm")]:{
        backgroundColor: 'white',
        color: '#555',
        border: '1px solid #ece7e7'
    }
},
}));

const LeftBar = () => {
  const classes = useStyles();
  return (
    <Container className={classes.container}>
      <div className={classes.item}>
        <Home className={classes.icon} />
        <Typography className={classes.text}>HomePage</Typography>
      </div>
      <div className={classes.item}>
        <Home className={classes.icon} />
        <Typography className={classes.text}>HomePage</Typography>
      </div>
      <div className={classes.item}>
        <Home className={classes.icon} />
        <Typography className={classes.text}>HomePage</Typography>
      </div>
      <div className={classes.item}>
        <Home className={classes.icon} />
        <Typography className={classes.text}>HomePage</Typography>
      </div>
    </Container>
  );
};

export default LeftBar;

【问题讨论】:

    标签: css reactjs material-ui


    【解决方案1】:

    如果您想快速修复,请将 sx 属性指定给您的图标,然后将所需的字体大小放在那里。

    <Home sx={{fontSize:"18px"}}/>
    

    否则请确保您的导入语句是正确的。

    ... from "@mui/material/styles"
    

    通常我将 mui 样式用于断点,所以类似于

     const IconWrapper = styled("div")(({ theme }) => ({
      marginRight: theme.spacing(1),
      [theme.breakpoints.up("sm")]: {
        fontSize: 18,
      },
    }));
    

    然后像这样实现它

    <IconWrapper>
       <Home />
    </IconWrapper>
    

    【讨论】:

    • 我需要通过添加不像你写的断点来改变大小
    • 更新了我的答案,希望对您有所帮助:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-24
    • 2016-08-02
    • 2019-11-10
    • 1970-01-01
    • 2020-08-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多