Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override Material UI .MuiContainer-maxWidthLg?

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

like image 890
Alex Chernilov Avatar asked May 06 '20 10:05

Alex Chernilov


People also ask

How do you import containers into material UI?

Step1: Create a React app using the following command. Step 2: Get into the project directory. Import Container: import Container from '@material-ui/core/Container';

How do I change the background color of container in material UI?

To set the background color of the Material UI drawer, we call the makeStyles function to create the styles. Then we can apply the styles with the useStyles hook returned by makeStyles . We call makeStyles with an object that has the properties set to objects with the styles.

How do you style a MUI container?

If you want a container to fill the full width of the screen, you need to use a nested selector so that your styling uses a more specific selector than the default MUI styling. For example, you can use the &. MuiContainer-maxWidthLg nested selector below. Class containerLg is applied on the container component.


1 Answers

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>
  );
}

Edit Container maxWidth

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

like image 163
Ryan Cogswell Avatar answered Oct 04 '22 09:10

Ryan Cogswell