简体   繁体   English

如何将卡片与 MUI 对齐?

[英]How do I align cards in center with MUI?

I've created a grid that displays cards using MUI, but the cards are 'stuck' to the left side of the page.我创建了一个使用 MUI 显示卡片的网格,但卡片“卡”在页面的左侧。 I've tried justify='center' , mx: 'auto' and alignItems='center' but the cards stay stuck to the left.我试过justify='center' , mx: 'auto'alignItems='center'但卡片仍然卡在左边。 I'm sure I'm using some prop that overrides my attempts, but I can't find documentation that speaks to my issue.我确定我正在使用一些可以覆盖我尝试的道具,但我找不到与我的问题相关的文档。 Below is the code:下面是代码:

export default function Home() {
  return (
    <Box sx={{ flexGrow: 1, mt: 6 }}>
      <Grid container spacing={{ xs: 2, md: 3 }} columns={{ xs: 4, sm: 8, md: 12 }}>
        {Array.from(Array(6)).map((_, index) => (
          <Grid item xs={2} sm={4} md={4} key={index}>
            <ProductCard />
          </Grid>
        ))}
      </Grid>
    </Box>
  );
}

Below is what React is rendering.下面是 React 正在渲染的内容。

什么反应正在渲染

you can to in grid like this:你可以像这样在网格中:

  <Grid item xs={2} sm={4} md={4} key={index} alignItems="center" justify="center">
     <ProductCard />
  </Grid>

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

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