I'm using Material UI to create the cards with grid container.
But Grid item will have same height for each row, how can I make the bottom card close to the top one when having white space? and the last card I wish to stick to the left instead of middle.
See the image below:
This is the look and feel I wish to achieve.
My example code:
codesandbox
Is it achievable by using Material Grid container or something else? or I have to create my own css? Please guide me. Thanks
I am able to achieve what I am try to by using flex-direction=column.
But I need split my data into few column, is it worth to do it?
Any other solution?
<Grid container spacing={3} className={classes.container}>
<Grid item xs={6} md={4} lg={3}>
<Grid container direction='column'>
<Grid item>
<Card></Card
</Grid>
</Grid>
</Grid>
</Grid>
<Grid item xs={6} md={4} lg={3}>
<Grid container direction='column'>
<Grid item>
<Card></Card
</Grid>
</Grid>
</Grid>
</Grid>
Related
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.
I have a Grid container and two "sub-containers" each taking half the space of the parent grid. I want to stack items of different heights on each of the sub-containers, but I'm having a problem with one side's height affecting the other.
The code is extremely simple:
<Box sx={{ flexGrow: 1 }}>
<Grid container spacing={3}>
<Grid item container xs={6}>
<Grid item xs={12}>
<Item>Short items</Item>
</Grid>
<Grid item xs={12}>
<Item>Short items</Item>
</Grid>
<Grid item xs={12}>
<Item>Short items</Item>
</Grid>
</Grid>
<Grid item container xs={6}>
<Grid item xs={6}>
<Item style={{ height: "450px" }}>Tall item</Item>
</Grid>
</Grid>
</Grid>
</Box>
And also a Codesandbox forked from the documentation's. The result I want is the items on the left stacking right on top of each other.
You can add alignContent="baseline" to your left Grid container like:
<Grid item container xs={6} alignContent="baseline">
You can take a look at this sandbox for a live working example of this usage.
I try to have a header on my application, where the left item (A) is aligned to the left side of the header, the second item (B) is in the center of the header and the third item is aligned to the right.
I tried a lot and found out that only this worked for me
const AppHeader = () => {
return(
<Grid container
alignItems="baseline"
>
<Grid item xs={4}>
<Grid container justify="flex-start">
A
</Grid>
</Grid>
<Grid item xs={4}>
<Grid container justify="center">
B
</Grid>
</Grid>
<Grid item xs={4}>
<Grid container justify="flex-end">
C
</Grid>
</Grid>
</Grid>
)
}
I think this is a ugly solution, because putting a container inside an item seems so unnecessary to me. Especially if we consider that this container has no grid items. I would really like to tell the item to align its content to a position. It would be better if this solution could be more like his:
const AppHeader = () => {
return(
<Grid container
alignItems="baseline"
>
<Grid item xs={4} justify="flex-start">
A
</Grid>
<Grid item xs={4} justify="center">
B
</Grid>
<Grid item xs={4} justify="flex-end">
C
</Grid>
</Grid>
)
}
Is there a way to do something similar like that?
Assuming you are using material-ui Grid component. You can do something like this
<Grid container direction="row" justify="space-between" alignItems="center">
<div>A</div>
<div>B</div>
<div>C</div>
</Grid>
CodeSandbox Link: https://codesandbox.io/s/small-haze-1wvtr
I am trying to make my label horizontally center in material UI using GRID API.
could you please tell me how I achieve this
https://codesandbox.io/s/007k3v472w
<div className="search-container">
<Grid container direction="row" spacing={24}>
<Grid item xs={6} className="abc">
<label>h</label>
</Grid>
<Grid item xs={6} className="pqr">
<label>hnnn</label>
</Grid>
</Grid>
</div>
https://material-ui.com/api/grid/
I already use alignItems but it not work
Expected out h and hnnn should be horizally center of their width.
currently they are left aligned
All you have to do add container attribute to each of your grid item and apply alignItem to make it center.
Your code should look something like this,
<Grid container direction="row" spacing={24}>
<Grid item xs={6}
container
direction="column"
justify="center"
alignItems="center"
className="abc">
<label>h</label>
</Grid>
<Grid item xs={6}
container
direction="column"
justify="center"
alignItems="center"
className="pqr">
<label>hnnn</label>
</Grid>
</Grid>
Let me know if it help!
Where you have defined your class as abc remove item and replace it with container and add justify="center"
To do it with CSS use text-align: center
I'm trying to achieve the following grid layout using the Grid component in Material UI.
I was able to achieve this layout in Chrome and Firefox using the following sample code, however in IE 11 all the grid items overlap and the textfields get expanded.
<Grid container direction='column' spacing={0}> // Grid 1 (Level0)
<Grid item xs={12}> // Grid 1 (Level1)
<Grid container direction='row' spacing={0}>
<Grid item xs={6}>
Logo
</Grid>
<Grid item xs={6}>
FormControl
</Grid>
</Grid>
</Grid>
<Grid item xs={12}> // Grid 2 (Level1)
<Grid container direction='column' spacing={0}>
<Grid item xs={12}> // Grid 1 (Level2)
<Grid container direction='row' spacing={0}>
<Grid item xs={12}>
<TextField/>
</Grid>
<Grid item xs={12}>
<TextField/>
</Grid>
</Grid>
</Grid>
<Grid item xs={12}> // Grid 2 (Level2)
<Grid container direction='row' spacing={0}>
<Grid item xs={6}>
<TextField />
</Grid>
<Grid item xs={6}>
<TextField />
</Grid>
</Grid>
</Grid>
</Grid>
</Grid>
<Grid item xs={12}> // Grid 3 (Level1)
<Grid container direction='row' spacing={0}>
<Grid item xs={6}>
Label
</Grid>
<Grid item xs={6}>
Label
</Grid>
</Grid>
</Grid>
</Grid>
Please let me know where am I going wrong!
According to the Material UI documentation, Material UI supports IE 11.
However, the Grid formatting issues as you describe them are a documented problem with a fix. The issues are a result of a Grid item not having the flex size set. In Chrome you can just use <Grid item>, but for IE you need to explicitly set the flex size <Grid item xs=12>.
How does this relate to you?
In your case it looks like your child <Grid container> components should also be <Grid item> components. That is, they should be of the form <Grid container item>, but they should also have the flex size set <Grid container item xs=12>.
Below is a sample snippet:
<Grid container>
<Grid item xs={12}>
<Grid container item xs={12}>
<Grid item xs={6}>
Logo
</Grid>
<Grid item xs={6}>
FormControl
</Grid>
</Grid>
</Grid>
</Grid>