gpt4 book ai didi

javascript - 网格元素不在彼此 Material UI 旁边

转载 作者:行者123 更新时间:2023-11-28 14:48:04 27 4
gpt4 key购买 nike

我在 material-ui 中使用 Grid 组件。我无法让网格元素相互堆叠。现在他们正在彼此堆叠。我不确定是什么让它们堆叠在一起。我已经这样做了,所以只有在小屏幕上网格元素才会堆叠在一起,否则每个网格元素应该占据 4 列。我在前端使用 react 。这是我的代码:

网格项:

   const styles = theme => ({

image: {
maxWidth: "100%",
maxHeight: "100%"
},


});
render() {
const { post, auth, classes } = this.props;
<div className={classes.root}>
<Link to={`/post/${post._id}`}>
<Grid
item
key={post.key}
sm={12}
md={4}
lg={4}

>
<img src={post.productImage} className={classes.image} />
<Typography>
{post.name}
<br />
{post.size}
</Typography>

</Grid>
</Link>
</div>

后馈:

 render() {
const { posts } = this.props;

return posts.map(post => <ListingPost key={post._id} post={post} />);
}
}

网格:常量样式 = 主题 => ({

  root: {
display: "flex",
flexWrap: "wrap",
justifyContent: "space-around",
overflow: "hidden",
backgroundColor: theme.palette.background.paper,
margin: 0
},

grid: {
margin: "auto",
width: "80%",
display: "inner-block"
},
paper: {
margin: "1%",
padding: "1%",
width: "80%"
},

});
render() {
const { classes } = this.props;
const { posts, loading } = this.props.post;
let postContent;

if (posts === null || loading) {
postContent = <div> loading</div>;
} else {
postContent = <PostFeed posts={posts} />;
}

return (
<div className={classes.root}>
<Paper className={classes.paper}>
<Typography align="center" variant="display2">
Listings
</Typography>
<Grid container className={classes.grid} spacing={16}>
{postContent}
</Grid>
</Paper>
</div>
);
}
}

最佳答案

如Yash Rahurikar所说,去掉Grid样式的flexWrap: "wrap"行,添加wrap='nowrap'你的网格容器。

关于javascript - 网格元素不在彼此 Material UI 旁边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52007957/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com