材质 UI 间距错误的间隙放置

问题描述 投票:0回答:1

我在 React 项目中使用 Material UI 5,代码如下:

    <Stack>
      <Stack
        flexDirection="row"
        justifyContent="center"
        padding={4}
        spacing={{ xs: 4 }}
      >
        {/* <MemoizedPlace {...place} key={place._id} /> */}
        <Box bgcolor={"red"} width={"200px"} height={"200px"}>
        <Box bgcolor={"green"} width={"200px"} height={"200px"}>
        {/* 
              <SideComments placeId={place._id} />
              <SideComments placeId={place._id} /> */}

        {/* <SideComments placeId={place._id} /> */}
      </Stack>
    </Stack>

此代码为我提供了照片中的框,其边距是我在第二个框顶部指定的边距,而不是框之间的边距。它似乎可以与间隙配合使用,但为什么间距不起作用

预期the right way of spacing 实际wrong top margin added to the second box

我试图在水平轴上获得项目之间的间距

css reactjs material-ui flexbox alignment
1个回答
0
投票

您只需将属性

flexDirection="row"
更改为
direction="row"
:

    <Stack>
      <Stack
        direction="row"
        justifyContent="center"
        padding={4}
        spacing={{ xs: 4 }}
      >
        {/* <MemoizedPlace {...place} key={place._id} /> */}
        <Box bgcolor={"red"} width={"200px"} height={"200px"}>
        <Box bgcolor={"green"} width={"200px"} height={"200px"}>
        {/* 
              <SideComments placeId={place._id} />
              <SideComments placeId={place._id} /> */}

        {/* <SideComments placeId={place._id} /> */}
      </Stack>
    </Stack>
© www.soinside.com 2019 - 2024. All rights reserved.