简体   繁体   English

如何在中心对齐startIcon材质ui图标?

[英]How to align startIcon material ui icon at the center?

I'm attempting to keep the icon button center aligned, but something isn't working right.我正在尝试保持图标按钮中心对齐,但有些东西不能正常工作。 Adding left: "0.5rem" to sx prop is pushing the button icon further.向 sx 道具添加 left: "0.5rem" 进一步推动按钮图标。 I'm trying not to use makeStyles to override the position.我试图不使用 makeStyles 来覆盖 position。 Any tip/direction would be helpful:)任何提示/方向都会有所帮助:)

Sandbox link 沙盒链接

You can try using style:您可以尝试使用样式:

<Stack direction="row" style={{display:"flex", justifyContent:"center", alignItems:"center"}}>
  <Tooltip title="Delete">
    <Button sx={{ minWidth: 0 }} startIcon={<DeleteIcon />} />
  </Tooltip>
  <Divider orientation="vertical" flexItem />
  <Tooltip title="Send">
    <Button sx={{ minWidth: 0 }} startIcon={<SendIcon />} />
  </Tooltip>
  <Tooltip title="Headset">
    <Button sx={{ minWidth: 0 }} startIcon={<HeadsetMicOutlined />} />
  </Tooltip>
  <Divider orientation="vertical" flexItem />
</Stack>

In case you want to set it in you theme here is how you can do it so you don't have to do it in every Button component.如果你想在你的主题中设置它,你可以这样做,这样你就不必在每个 Button 组件中都这样做。

export const theme = createTheme({
  ...
  components: {
    MuiButton: {
      styleOverrides: {
        startIcon: {
          margin: '0'
        },
      },
    }
  },
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM