[英]MaterialUI show and hide the Container's gutters based on breakpoints
我想禁用xs
、 sm
和md
的裝訂線。 並在xl
及以后啟用它們。
然而,這是行不通的。
<Container maxWidth={"xl"} disableGutters={{ xs: true, xl: false }}>
我是不是做錯了什么——因為 API 提到 boolean 可以傳遞給disableGutters
?
正如@Mr.Polywhirl 所說,disableGutters只接受布爾值,您可以按如下方式解決它:
function Layout({children}) { const theme = useTheme(); const lessThanXL = useMediaQuery(theme.breakpoints.down("xl")); return <Container maxWidth="xl" disableGutters={lessThanXL}>{children}</Container> }
disableGutters
道具僅接受 boolean,因此您使用的 API 錯誤。
容器 API - 道具
姓名 類型 默認 描述 disableGutters
bool
false
如果為 true
,則移除左右填充。
所以你的代碼必須看起來像這樣
<Container maxWidth={"xl"} disableGutters={false}>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.