Full Width Material-UI Grid not working as it should










2















I am trying to understand Material-UI@next grid layout system.



My goal is to have two papers that expand through the whole width screen and break whenever the screen gets smaller to just one paper. The documentation has the following code snippet:



 <Container>
<Grid container spacing=24>
<Grid item xs=12>
<Paper>xs=12</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
</Grid>
</Container>


This results in the following:
enter image description here



I then modified the code to try to achieve my goal of just two papers, as this:



 <Container>
<Grid container spacing=24>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
</Grid>
</Container>


But as you can see, this results into two papers which are not taking the whole screen:
enter image description here



Can someone point me to a working example snippet that allows me to have two elements that take the full width?










share|improve this question






















  • Any luck with my answer?

    – Paul Mcloughlin
    Apr 12 '18 at 14:05















2















I am trying to understand Material-UI@next grid layout system.



My goal is to have two papers that expand through the whole width screen and break whenever the screen gets smaller to just one paper. The documentation has the following code snippet:



 <Container>
<Grid container spacing=24>
<Grid item xs=12>
<Paper>xs=12</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
</Grid>
</Container>


This results in the following:
enter image description here



I then modified the code to try to achieve my goal of just two papers, as this:



 <Container>
<Grid container spacing=24>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
</Grid>
</Container>


But as you can see, this results into two papers which are not taking the whole screen:
enter image description here



Can someone point me to a working example snippet that allows me to have two elements that take the full width?










share|improve this question






















  • Any luck with my answer?

    – Paul Mcloughlin
    Apr 12 '18 at 14:05













2












2








2


1






I am trying to understand Material-UI@next grid layout system.



My goal is to have two papers that expand through the whole width screen and break whenever the screen gets smaller to just one paper. The documentation has the following code snippet:



 <Container>
<Grid container spacing=24>
<Grid item xs=12>
<Paper>xs=12</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
</Grid>
</Container>


This results in the following:
enter image description here



I then modified the code to try to achieve my goal of just two papers, as this:



 <Container>
<Grid container spacing=24>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
</Grid>
</Container>


But as you can see, this results into two papers which are not taking the whole screen:
enter image description here



Can someone point me to a working example snippet that allows me to have two elements that take the full width?










share|improve this question














I am trying to understand Material-UI@next grid layout system.



My goal is to have two papers that expand through the whole width screen and break whenever the screen gets smaller to just one paper. The documentation has the following code snippet:



 <Container>
<Grid container spacing=24>
<Grid item xs=12>
<Paper>xs=12</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
<Grid item xs=6 sm=3>
<Paper>xs=6 sm=3</Paper>
</Grid>
</Grid>
</Container>


This results in the following:
enter image description here



I then modified the code to try to achieve my goal of just two papers, as this:



 <Container>
<Grid container spacing=24>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
</Grid>
</Container>


But as you can see, this results into two papers which are not taking the whole screen:
enter image description here



Can someone point me to a working example snippet that allows me to have two elements that take the full width?







css reactjs material-design material-ui






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 12 '18 at 12:59









James J.James J.

8141818




8141818












  • Any luck with my answer?

    – Paul Mcloughlin
    Apr 12 '18 at 14:05

















  • Any luck with my answer?

    – Paul Mcloughlin
    Apr 12 '18 at 14:05
















Any luck with my answer?

– Paul Mcloughlin
Apr 12 '18 at 14:05





Any luck with my answer?

– Paul Mcloughlin
Apr 12 '18 at 14:05












1 Answer
1






active

oldest

votes


















8














I suspect the Container component is causing you problems. Since you haven't linked its implementation, see below for a working example of what you want.



Since Material uses flexbox they make use of property flexGrow




The flex-grow CSS property specifies the flex grow factor of a flex item. It specifies what amount of space inside the flex container the item should take up. The flex grow factor of a flex item is relative to the size of the other children in the flex-container.




This is the property that governs the growth of elements in the grid.



import React from 'react';
import PropTypes from 'prop-types';
import withStyles from 'material-ui/styles';
import Paper from 'material-ui/Paper';
import Grid from 'material-ui/Grid';

const styles = theme => (
root:
flexGrow: 1,
,
paper:
padding: theme.spacing.unit * 2,
textAlign: 'center',
color: theme.palette.text.secondary,
,
);

function CenteredGrid(props)
const classes = props;

return (
<div className=classes.root>
<Grid container spacing=24>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
</Grid>
</div>
);


CenteredGrid.propTypes =
classes: PropTypes.object.isRequired,
;

export default withStyles(styles)(CenteredGrid);





share|improve this answer

























  • I don't get the role of your flex-grow:1 here. It works for flex items only and here this div is a top level tag... Working example without it... codesandbox.io/s/mm2vwpljr9

    – Tomek
    Dec 21 '18 at 23:13










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49797264%2ffull-width-material-ui-grid-not-working-as-it-should%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









8














I suspect the Container component is causing you problems. Since you haven't linked its implementation, see below for a working example of what you want.



Since Material uses flexbox they make use of property flexGrow




The flex-grow CSS property specifies the flex grow factor of a flex item. It specifies what amount of space inside the flex container the item should take up. The flex grow factor of a flex item is relative to the size of the other children in the flex-container.




This is the property that governs the growth of elements in the grid.



import React from 'react';
import PropTypes from 'prop-types';
import withStyles from 'material-ui/styles';
import Paper from 'material-ui/Paper';
import Grid from 'material-ui/Grid';

const styles = theme => (
root:
flexGrow: 1,
,
paper:
padding: theme.spacing.unit * 2,
textAlign: 'center',
color: theme.palette.text.secondary,
,
);

function CenteredGrid(props)
const classes = props;

return (
<div className=classes.root>
<Grid container spacing=24>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
</Grid>
</div>
);


CenteredGrid.propTypes =
classes: PropTypes.object.isRequired,
;

export default withStyles(styles)(CenteredGrid);





share|improve this answer

























  • I don't get the role of your flex-grow:1 here. It works for flex items only and here this div is a top level tag... Working example without it... codesandbox.io/s/mm2vwpljr9

    – Tomek
    Dec 21 '18 at 23:13















8














I suspect the Container component is causing you problems. Since you haven't linked its implementation, see below for a working example of what you want.



Since Material uses flexbox they make use of property flexGrow




The flex-grow CSS property specifies the flex grow factor of a flex item. It specifies what amount of space inside the flex container the item should take up. The flex grow factor of a flex item is relative to the size of the other children in the flex-container.




This is the property that governs the growth of elements in the grid.



import React from 'react';
import PropTypes from 'prop-types';
import withStyles from 'material-ui/styles';
import Paper from 'material-ui/Paper';
import Grid from 'material-ui/Grid';

const styles = theme => (
root:
flexGrow: 1,
,
paper:
padding: theme.spacing.unit * 2,
textAlign: 'center',
color: theme.palette.text.secondary,
,
);

function CenteredGrid(props)
const classes = props;

return (
<div className=classes.root>
<Grid container spacing=24>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
</Grid>
</div>
);


CenteredGrid.propTypes =
classes: PropTypes.object.isRequired,
;

export default withStyles(styles)(CenteredGrid);





share|improve this answer

























  • I don't get the role of your flex-grow:1 here. It works for flex items only and here this div is a top level tag... Working example without it... codesandbox.io/s/mm2vwpljr9

    – Tomek
    Dec 21 '18 at 23:13













8












8








8







I suspect the Container component is causing you problems. Since you haven't linked its implementation, see below for a working example of what you want.



Since Material uses flexbox they make use of property flexGrow




The flex-grow CSS property specifies the flex grow factor of a flex item. It specifies what amount of space inside the flex container the item should take up. The flex grow factor of a flex item is relative to the size of the other children in the flex-container.




This is the property that governs the growth of elements in the grid.



import React from 'react';
import PropTypes from 'prop-types';
import withStyles from 'material-ui/styles';
import Paper from 'material-ui/Paper';
import Grid from 'material-ui/Grid';

const styles = theme => (
root:
flexGrow: 1,
,
paper:
padding: theme.spacing.unit * 2,
textAlign: 'center',
color: theme.palette.text.secondary,
,
);

function CenteredGrid(props)
const classes = props;

return (
<div className=classes.root>
<Grid container spacing=24>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
</Grid>
</div>
);


CenteredGrid.propTypes =
classes: PropTypes.object.isRequired,
;

export default withStyles(styles)(CenteredGrid);





share|improve this answer















I suspect the Container component is causing you problems. Since you haven't linked its implementation, see below for a working example of what you want.



Since Material uses flexbox they make use of property flexGrow




The flex-grow CSS property specifies the flex grow factor of a flex item. It specifies what amount of space inside the flex container the item should take up. The flex grow factor of a flex item is relative to the size of the other children in the flex-container.




This is the property that governs the growth of elements in the grid.



import React from 'react';
import PropTypes from 'prop-types';
import withStyles from 'material-ui/styles';
import Paper from 'material-ui/Paper';
import Grid from 'material-ui/Grid';

const styles = theme => (
root:
flexGrow: 1,
,
paper:
padding: theme.spacing.unit * 2,
textAlign: 'center',
color: theme.palette.text.secondary,
,
);

function CenteredGrid(props)
const classes = props;

return (
<div className=classes.root>
<Grid container spacing=24>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
<Grid item xs=12 sm=6>
<Paper>xs=12 sm=6</Paper>
</Grid>
</Grid>
</div>
);


CenteredGrid.propTypes =
classes: PropTypes.object.isRequired,
;

export default withStyles(styles)(CenteredGrid);






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 10:03

























answered Apr 12 '18 at 13:30









Paul McloughlinPaul Mcloughlin

1,2882917




1,2882917












  • I don't get the role of your flex-grow:1 here. It works for flex items only and here this div is a top level tag... Working example without it... codesandbox.io/s/mm2vwpljr9

    – Tomek
    Dec 21 '18 at 23:13

















  • I don't get the role of your flex-grow:1 here. It works for flex items only and here this div is a top level tag... Working example without it... codesandbox.io/s/mm2vwpljr9

    – Tomek
    Dec 21 '18 at 23:13
















I don't get the role of your flex-grow:1 here. It works for flex items only and here this div is a top level tag... Working example without it... codesandbox.io/s/mm2vwpljr9

– Tomek
Dec 21 '18 at 23:13





I don't get the role of your flex-grow:1 here. It works for flex items only and here this div is a top level tag... Working example without it... codesandbox.io/s/mm2vwpljr9

– Tomek
Dec 21 '18 at 23:13

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49797264%2ffull-width-material-ui-grid-not-working-as-it-should%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3