I have a problem with the order of stacking of grid items whenever browser shrinks.
This is what I want on the normal desktop screen(lg
):
---------------------------------------------
| col 1 | col 2 | col 3 |
---------------------------------------------
But After Shrinking the browser I am getting the following result:
-------------------------
| col 1 |
-------------------------
-------------------------
| col 2 |
-------------------------
-------------------------
| col 3 |
-------------------------
Can I with material ui Grid layout achieve this on a mobile screen:
-------------------------
| col 1 |
-------------------------
-------------------------
| col 3 |
-------------------------
-------------------------
| col 2 |
-------------------------
I have read articles on changing the order of CSS-grids for the same topic but how to achieve this using material-ui Grid layout.
Moving around grid items is simple. Just use the margin , the transform , or the position:relative; properties.
Material-UI Grid Align Right If you need to horizontally align using only CSS, remember that justify-content horizontally aligns using the following values: flex-start: horizontally aligns left. center: horizontally aligns center. flex-end: horizontally aligns right.
How the Order Property Works in Grid Layout. The order property can be used to specify the order in which different items should be placed inside a grid. By default, the items are placed in the order in which they appear in the DOM.
One of the easiest ways of centering the content of grid items is using Flexbox. Set the display to "grid" for the grid container, and "flex" for grid items. Then, add the align-items and justify-content properties, both with the "center" value, to grid items.
Edit: I have revised the answer for MUI Core v5
<Grid container spacing={16} justify="flex-start">
<Grid item xs={12} sm={6} md={4} lg={4}>
<Paper>
<h1>{1}</h1>
</Paper>
</Grid>
<Grid item xs={12} sm={6} md={4} lg={4} order={{ xs: 3, sm: 2 }}>
<Paper>
<h1>{2}</h1>
</Paper>
</Grid>
<Grid item xs={12} sm={6} md={4} lg={4} order={{ xs: 2, sm: 3 }}>
<Paper>
<h1>{3}</h1>
</Paper>
</Grid>
</Grid>
https://codesandbox.io/s/xvv7o07614?file=/src/GridStacking.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With