首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Material:使用<Divider>破坏网格

Material:使用<Divider>破坏网格
EN

Stack Overflow用户
提问于 2020-09-02 19:20:29
回答 5查看 12.8K关注 0票数 10

所以我有个烦人的问题我找不到结果。我对材料不熟悉,感觉好像我错过了什么.

我只想在网格项之间设置一个分隔符,而不是破坏网格的顺序。我遗漏了什么?

沙箱:https://vpbyd.csb.app/

代码语言:javascript
复制
import React from "react";
import "./styles.css";
import {Grid, Typography, Divider} from '@material-ui/core'

export default function App() {
  return (
    <div className="App">
       <Grid container spacing={3}>

<Grid item xs={4}> 
<Typography variant="h5" component="h2">
One
</Typography>
</Grid>
<Grid item xs={4}> 
<Typography variant="h5" component="h2">
  Two
  </Typography>
</Grid>
<Grid item xs={4}> 
<Typography variant="h5" component="h2">
  Three
  </Typography>
</Grid>

</Grid>

<Grid container spacing={0} alignItems="center">

<Grid item xs={4}> 
<Typography variant="h6" component="h2">
first value
</Typography>
</Grid>
<Divider orientation="vertical" flexItem/>
<Grid item xs={4}> 
<Typography variant="h6" component="h2">
second value
</Typography>
</Grid>
<Divider orientation="vertical" flexItem/>
<Grid item xs={4}> 
<Typography variant="h6" component="h2">
third value
</Typography>
</Grid>

</Grid>
    </div>
  );
}
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2020-09-02 19:25:58

尝试将分隔符放入其自己的网格容器中。

代码语言:javascript
复制
<Grid item xs={2}> 
   <Divider orientation="vertical" flexItem/>
</Grid>

material网格使用的是柔性盒,因此在其中删除不具有正确属性的项会使网格陷入混乱。

票数 9
EN

Stack Overflow用户

发布于 2021-03-19 13:49:58

我有同样的问题,并发现了一个窍门:给你的分区增加一个负的右边距。

代码语言:javascript
复制
<Grid item xs={4}> 
    <Typography variant="h6" component="h2">
        first value
    </Typography>
</Grid>
<Divider orientation="vertical" flexItem sx={{ mr: "-1px" }} />
<Grid item xs={4}> 
    <Typography variant="h6" component="h2">
        second value
    </Typography>
</Grid>
票数 13
EN

Stack Overflow用户

发布于 2021-08-18 12:16:19

对我来说,一个很好的通用解决方案是添加这种全局样式。

代码语言:javascript
复制
.MuiGrid-container > .MuiDivider-vertical.MuiDivider-flexItem {
  margin-right: -1px;
}

与将JSX属性flexItem添加到Divider相结合

代码语言:javascript
复制
<Grid container>
  <Grid item xs={4}>
    ...
  </Grid>
  <Divider flexItem orientation="vertical" />
  <Grid item xs={8}>
    ...
  </Grid>
</Grid>

这是一个干净的,透明的解决办法,使网格按预期运行。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63712269

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档