I am using MUI Grid
structure in ReactJs to display 5 columns like this:
In smaller screens the columns are moving in the next row. But In smaller screens I also want all the columns to show in one row only and I can access other columns by scrolling horizontally.
<Grid
container
spacing={2}
style={{
maxHeight: "100vh",
overflowY: "auto",
overflowX: "hidden",
height: "440px",
overflow: "auto",
}}
>
<Grid item xs={2.1}>
{cards.map((card) => <Card props={card} /> )}
</Grid>
</Grid>
Because Grid
uses flexbox under the hood. You can simply set the wrap
value to nowrap
in your Grid
container, you can see the full API of Grid
component here.
<Grid
container
wrap="nowrap" // --> add this line to disable wrap
sx={{ overflow: "auto" }} // --> add scrollbar when the content inside is overflowed
spacing={8}
>
{...}
</Grid>
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