reactjs - 在 Material-UI 容器中使用断点

标签 reactjs material-ui

我用 容器 并且它需要为移动设备和桌面设备提供不同的大小。
我怎样才能拥有 容器 maxWidth不同尺寸基于 断点 像这样:

<Container maxWidth={{xs:"lg", lg:"md"}}>
而不是使用 useStyle 并添加一个 className .

最佳答案

您可以使用 sx 来做到这一点。支撑responsive values的 Prop .断点值可以在 theme.breakpoints.values 中访问目的。见 default theme在这里了解更多。

const theme = useTheme();
<Container
  sx={{
    bgcolor: "wheat",
    maxWidth: {
      lg: theme.breakpoints.values["md"],
      md: 80,
      xs: 20
    }
  }}
>
  <Box sx={{ bgcolor: "#cfe8fc", height: "100vh", width: "100%" }} />
</Container>
Codesandbox Demo

关于reactjs - 在 Material-UI 容器中使用断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69538083/

相关文章:

javascript - 通过 onKeyPress 或 onKeyDown 在 React 中仅允许数字

reactjs - 如何让 webpack 转换 React 生产文件?

css - 将禁用时的 TextField 的 borderBottom 样式更改为 'none' ?

css - 在 Material UI 中使用 calc()

reactjs - 如何使用 SpeedDial 上传文件?

javascript - Material-ui 库中的 Event.ctrlKey 始终为 true

javascript - 删除 URL 参数 JS ES6

node.js - 如何从父目录导入 npm 模块?

javascript - JS - React - map() 方法对元素索引进行过滤(仅在索引满足条件时运行)

javascript - 此堆快照保留器层次结构是否表明存在泄漏?