css - Material UI Grid Items 不占全宽度
问题描述
我在 Material UI 中使用嵌套网格系统,网格项目仅采用固定宽度并留下一些空间。当固定空间被耗尽时,组件并没有挤压它们内部的可用空间,而是破坏了 UI。
为清楚起见,请参阅屏幕截图(在 Google Chrome 中拍摄的所有屏幕截图)。
外部网格的片段
<Grid container justifyContent="space-evenly" direction={isMd ? "row" : "column"}>
<Grid item sx={{ minWidth: "300px" }}>
<Typography>Component coming soon</Typography>
</Grid>
<Grid item component={Footer2}></Grid>
</Grid>
内部网格的片段
<Grid
container
justifyContent="space-evenly"
direction={isMd ? "row" : "column"}
gap={6}
>
<Grid item links={["COMPANY", "About", "Experts and Spokesmodels"]}>
<Listings
links={["COMPANY", "About", "Experts and Spokesmodels"]}
></Listings>
</Grid>
<Grid item>
<Listings
links={[
"CUSTOMER SERVICE",
"Contact Us",
"My Account",
"Store Locator",
"Redeem Rewards"
]}
></Listings>
</Grid>
<Grid item>
<Listings
links={[
"MORE TO EXPLORE",
"Beauty Magazine",
"Tools and Consultations",
"Offers",
"#LorealParis"
]}
></Listings>
</Grid>
</Grid>
解决方案
只需在 FooterP2.js 中删除 Grid 组件的 gap props,为 ScopedCssBaseline 添加 CSS 规则并为元素设置 maxWidth(例如我设置了 800px)。
<ThemeProvider theme={darkTheme}>
<ScopedCssBaseline
style={{ flex: "1 1 auto", maxWidth: "800px" }}>
<Grid
container
justifyContent="space-evenly"
direction={isMd ? "row" : "column"}
>
推荐阅读
- javascript - Mapbox Terrain:在样式表达式中引用 DEM 值
- c++ - 如何从另一个命名空间中扩展 C++ 命名空间?
- matlab - 在matlab眼图中是否有任何代码可以执行“打印到图形”?
- oracle-nosql - Oracle NoSQL 错误:[ILLEGAL_ARGUMENT] PUT:非法参数:不应为生成的始终标识列设置值:id
- python - 如何检查文件夹是否存在并使用python创建文件夹
- android - 一种对android应用文件进行版本控制的方法?
- istio - 删除 Istio Sidecar 的报告指标
- javascript - 我是新手,我正在关注 freecodecamp 上的本教程。我被困在待办事项列表上,但我的代码与教程中的相同
- vue.js - 每次在捕获错误Axios中重定向到另一个页面时页面都会刷新
- java - Keycloak Twilio NoClassDefFoundError