【发布时间】:2020-11-04 11:39:35
【问题描述】:
我正在尝试将两个网格项与 Material UI 重叠,但在尝试不同的方法后我失败了,如果有人能指出我正确的方向。
所以基本上试图将 item 2 居中并让 item 1 大约 1/3 进入 item 2强>.
<Grid
container
direction="column"
justify="flex-start"
alignItems="flex-start"
style={{ width: "100%", height: "100%", background: "pink" }}
>
<Grid
item
container
xs={4}
style={{ width: "100%", height: "100%", background: "blue" }}
>
1
</Grid>
<Grid
item
xs={6}
style={{ width: "100%", height: "100%", background: "red" }}
>
<Grid
item
xs={2}
justify="center"
style={{ width: "10", background: "grey" }}
>
<h1>2/2</h1>
</Grid>
</Grid>
<Grid
item
xs={4}
style={{ width: "100%", height: "100%", background: "brown" }}
>
3
</Grid>
</Grid>
</div>
【问题讨论】:
-
很确定您不想为此使用网格。根据定义,网格项目以网格布局,而不是重叠。
-
嗨,JMadelaine!哦,我是新手,我认为网格是一个快速的解决方案。请让我知道您推荐什么方法?谢谢!
-
如果您是 React 和一般开发新手,我不会使用 Material UI 之类的第三方库,而是开始构建您自己的组件。这样你会更容易理解发生了什么。
-
我担心 JMadelaine 可能有点夸大了这个案例。如果可以在 material-ui 中找到解决方案,那么我认为提供该解决方案比将一个自称是新手的人送入 React、JSX 和样式的荒野要好得多。
标签: reactjs responsive-design grid material-ui