【发布时间】:2021-04-26 23:16:58
【问题描述】:
我正在使用 Material UI Grid 来制作图像网格,并且我正在尝试消除一些网格项之间的空白。我尝试更改容器的 alignitems 和 justify 值,但没有奏效。
见图片。
return <Grid container alignItems="flex-start" justify="center" className="img-container" spacing={2}>
{/* All images */}
{docs && docs
.map(image => (
// In a grid item
<Grid className="img-item" item key={image.id} xs={12} md={6} lg={4}>
{/* all accounts */}
{docs2 && docs2
.filter((user) => image.userID === user.userID)
.map(user => (
<div key={image.id} className="div">
<img src={image.url} alt="uploaded pic" />
<Typography variant="subtitle1"> By {user.userName}
{/* Delete button only renders if currentUser.uid === image.userID*/}
{handleButton(image.userID) &&
<IconButton
color="secondary" aria-label="delete image"
onClick={() => handleDeleteImage(image.id,
image.userID, image.name)}
component="span" >
<DeleteForever />
</IconButton>}
</Typography>
</div>
))}
</Grid>
))}
</Grid>
}
【问题讨论】:
-
在图像的情况下,间距还取决于图像的尺寸。如果图像不是
GridItem要求的高度,或者图像的高度不同(看这里),那么会有一些空白空间.. -
所以不能根据里面的图片来调整grid item的高度吗?
标签: javascript reactjs firebase material-ui jsx