Grid Alignment Issues - reactjs

What I need to produce is 3 grid items on the left and 2 grid items on the right. I tried using float on the second grid container but it didn't work the way I wanted to. The Grids also contain elements like Checkboxes so I'm not sure if that changes the alignment.
<Grid container xs={12} md={6}>
<Grid item xs={12} md={6}> 1 </Grid>
<Grid item xs={12} md={6}> 2</Grid>
<Grid item xs={12} md={6}> 3</Grid>
</Grid>
<Grid container xs={12} md={6}>
<Grid item xs={12} md={6}> 4 </Grid>
<Grid item xs={12} md={6}> 5</Grid>
</Grid>
Expected:
md:
1 4
2 5
3
Actual:
md:
1 4
2
5
3
xs:
1
2
3
4
5

You could put both columns into another container and make them it's items:
<Grid container>
<Grid item xs={12} md={6}>
<Grid item xs={12} md={6}>1</Grid>
<Grid item xs={12} md={6}>2</Grid>
<Grid item xs={12} md={6}>3</Grid>
</Grid>
<Grid item xs={12} md={6}>
<Grid item xs={12} md={6}>4</Grid>
<Grid item xs={12} md={6}>5</Grid>
</Grid>
</Grid>

Related

Item content not center aligns in Grid and irregular height Material UI

I am trying to use MUI Card in Grid layout
<Grid container spacing={5} alignContent="center" alignItems="center" justifyContent="center" columnSpacing={{ xs: 1, sm: 2, md: 3 }}>
<Grid item xs={4} md={6} alignItems="center">
<Card />
</Grid>
<Grid item xs={4} md={6}>
<Card />
</Grid>
<Grid item xs={4} md={6}>
<Card />
</Grid>
<Grid item xs={4} md={6}>
<Card />
</Grid>
</Grid>
But the problem is its not center aligns with in each grid item. I have added border for each item
What I did wrong?
Also as you can see the grid overlap on the title above

MUI Grid: items do not change their width despite defining the columns for items

So i was following a tutorial, where the items would change depending on the size of the screen. And would take up the whole width if defined the following way:
class App extends Component {
render() {
return (
<div>
<Grid container>
<Grid>
<Paper item xs={12} sm={6} md={3}>1</Paper>
</Grid>
<Grid>
<Paper item xs={12} sm={6} md={3}>2</Paper>
</Grid>
<Grid>
<Paper item xs={12} sm={6} md={3}>3</Paper>
</Grid>
<Grid>
<Paper item xs={12} sm={6} md={3}>4</Paper>
</Grid>
</Grid>
</div>
);
}}
Well for me, no matter the width of my screen it always looks like this:
I see no reason for it not to work, but somehow the elements don't stretch to take up the complete width of the screen.
The mistake you are doing here is that you are adding the Grid properties (item xs={12} sm={6} md={3}) in the Paper component instead of the Grid item.
Here is the right code:
return (
<div>
<Grid container>
<Grid item xs={12} sm={6} md={3}>
<Paper>1</Paper>
</Grid>
<Grid item xs={12} sm={6} md={3}>
<Paper>2</Paper>
</Grid>
<Grid item xs={12} sm={6} md={3}>
<Paper>3</Paper>
</Grid>
<Grid item xs={12} sm={6} md={3}>
<Paper>4</Paper>
</Grid>
</Grid>
</div>
);
Here is a working codesandbox with your example

MUI Grid xs item doesn't shrink

I've created a small Dashboard in order to view achievements of some sort (won't get into details). The page consists in small boxes with certain information and to make them responsive I've used MUI Grid.
<Box>
<Grid container spacing={3}>
<Grid item xs={12} md={6} lg={6}>
<SelfNumberOfQuizzes />
</Grid>
<Grid item xs={12} md={6} lg={6}>
<SelfPointsInPeriod period={period} />
</Grid>
</Grid>
<Grid container spacing={3} mt={1.5}>
<Grid item xs={12} md={6} lg={6}>
<SelfNumberOfQuizzesByDifficulty />
</Grid>
<Grid item xs={12} md={6} lg={6}>
<SelfPointsByDifficultyInPeriod period={period} />
</Grid>
</Grid>
<Grid container spacing={3} mt={1.5}>
<Grid item xs={12} md={12} lg={12}>
<SelfAnswersByDifficulty />
</Grid>
</Grid>
</Box>
The page looks good and it works just fine when trying to shrink when lg or md (the inside items shrinks as well to be fully visible). However, once the page is small enough to use xs prop, the items don't shrink anymore, the width looks fixed.
First picture -> MD
Second picture -> XS
You can see the horizontal scroll bar when it starts to be XS. The components within each grid item don't have width specified.

No duplicate props allowed react/jsx-no-duplicate-props

I am getting this error on line Grid item :
<Grid container spacing={3} className='centerd-text' >
<Grid item xs={12} xs={12} md={4} >
<img src={img01} alt="img" />
</Grid>
</Grid>
Please remove one xs={12} in Grid

Change Grid item column order on small screens

I'm attempting to have a grid looking like this for larger displays:
and this for smaller sizes:
Currently the skeleton of my grid is succinctly like this:
<Fragment>
<Grid container spacing={3}>
<Grid item xs={12} md={6}>
<img src={img1} />
</Grid>
<Grid item xs={12} md={6}>
<Paper>Text Content 1...</Paper>
</Grid>
</Grid>
<Grid container spacing={3}>
<Grid item xs={12} md={6}>
<Paper>Text Content 2...</Paper>
</Grid>
<Grid item xs={12} md={6}>
<img src={img2} />
</Grid>
</Grid>
</Fragment>
How can I do such as in mobile view (width 12) the first Grid item from the second Grid container (Text content 2) displays after (below) the image?
Use like this:
<Grid container>
<Grid spacing={3} container item xs={12} md={12}>
<Grid item xs={12} md={6} className={classes.item}>
<img
width="50px"
src="https://cdn3.vectorstock.com/i/1000x1000/37/37/simple-cartoon-a-cute-bear-vector-18823737.jpg"
alt="abc"
/>
</Grid>
<Grid container item xs={12} md={6} className={classes.item}>
<Paper>Text Content 1...</Paper>
</Grid>
</Grid>
<Grid container item spacing={3} xs={12} md={12} className="flexgrid">
<Grid container item xs={12} md={6} className={classes.item}>
<Paper>Text Content 2...</Paper>
</Grid>
<Grid container item xs={12} md={6} className={classes.item}>
<img
width="50px"
src="https://cdn3.vectorstock.com/i/1000x1000/37/37/simple-cartoon-a-cute-bear-vector-18823737.jpg"
alt="abd"
/>
</Grid>
</Grid>
</Grid>
SOURCE
PREVIEW
for re-order added:
<Grid container item spacing={3} xs={12} md={12} className="flexgrid">
and css :
#media screen and (max-width: 720px) {
.flexgrid{
flex-direction: column-reverse
}
}

Resources