【发布时间】:2019-02-23 18:15:38
【问题描述】:
我尝试了一切,但似乎我错过了一些东西。当屏幕特别小时,我一直在尝试在网格内制作一个按钮中心。
此代码完美运行,但问题是我希望我的按钮仅在屏幕超小而不是所有尺寸时居中。
工作代码。
Grid item xs={12}>
<Grid container justify="center">
<Button color="primary" variant="raised">
Add Product
</Button>
</Grid>
</Grid>
代码无效...
Grid item xs={12}>
<Grid container className={"justify-xs-center"}>
<Button color="primary" variant="raised">
Add Product
</Button>
</Grid>
</Grid>
我一直在阅读 Grid 的 API 文档,据我了解这是在组件中添加预定义类的正确方法,但效果似乎不起作用。当我按预期在 Grid 容器组件上找到类 justify-xs-center 来检查元素时。
感谢您的帮助。
【问题讨论】:
-
给包含按钮的父容器一个宽度,可能是 100%,然后设置 margin-left: "auto" 和 margin-right: "auto" 使里面的内容居中。检查你的 html 元素也有助于了解为什么 flex 不起作用
-
谢谢朋友,我只是假设material-ui的CSS API有问题
-
这不是一个不常见的想法,但大多数时候在这些情况下极不可能。干杯哥们
-
我发现自己处于类似的情况,我所期望的是像
justify-xs-center加上justify-sm-flex-start,但没有这样的东西:( 看来我们需要写媒体查询
标签: reactjs css-selectors material-ui react-component