How to override Material UI .MuiContainer-maxWidthLg?

故事扮演 提交于 2020-12-10 08:50:05

问题


I'm trying to get rid of max-width that present in the theme.
This is what I see in Chrome (and if I uncheck it, it does what I need):

@media (min-width: 1280px)
.MuiContainer-maxWidthLg {
    max-width: 1280px;
}

How can I do this? I tried something like this:

const useStyles = makeStyles(theme => ({
    root: {       
        '& .MuiContainer-maxWidthLg' : {
             maxWidth: //No matter what I put here, it does not work
        }, 

but it does not seem to have any effect... How can I override this?

Thanks,

Alex


回答1:


The maxWidth prop of Container defaults to 'lg', but you can prevent Material-UI trying to control the max width of the Container by setting maxWidth={false}.

Here's a simple example:

import React from "react";
import Container from "@material-ui/core/Container";
import Paper from "@material-ui/core/Paper";

export default function App() {
  return (
    <Container maxWidth={false}>
      <Paper>
        <h1>Hello CodeSandbox</h1>
      </Paper>
    </Container>
  );
}

Related documentation: https://material-ui.com/api/container/#props

Code reference: https://github.com/mui-org/material-ui/blob/v4.9.13/packages/material-ui/src/Container/Container.js#L88




回答2:


You can still achieve this with makeStyles:

const useStyles = makeStyles((theme) => ({
  root: {
    [theme.breakpoints.up('lg')]: {
      maxWidth: <YourMaxWidth>px,
    },
  },
}))



回答3:


Well, setting the following in a parent div worked:

'& .MuiContainer-maxWidthLg' : {
      maxWidth: '100%'
}, 


来源:https://stackoverflow.com/questions/61633192/how-to-override-material-ui-muicontainer-maxwidthlg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!