Skip to content

Commit 922c915

Browse files
authored
Merge pull request #269 from tryoxiss/main
grid-container: allow the grid to shrink to fit all avalible space to prevent sidescroll.
2 parents 26d58a5 + dea6aaf commit 922c915

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

snippets/css/layouts/grid-layout.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
title: Grid layout
33
description: Equal sized items in a responsive grid
44
author: xshubhamg
5+
contributors: tryoxiss
56
tags: layout,grid
67
---
78

89
```css
910
.grid-container {
10-
display: grid
11-
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
11+
display: grid;
12+
grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr));
1213
/* Explanation:
1314
- `auto-fit`: Automatically fits as many columns as possible within the container.
14-
- `minmax(250px, 1fr)`: Defines a minimum column size of 250px and a maximum size of 1fr (fraction of available space).
15+
- `minmax(min(250px, 100%), 1fr)`: Defines a minimum column size of 250px and a maximum size of 1fr (fraction of available space). However, that minimum column size is allowed to shrink to fit all avalible space if the space is otherwise less than the minimum.
16+
- NOTE: the `min(x, 100%)` trick does not do much for very small sizes like 250px, but it will help massively if you increase the min column size yourself.
1517
*/
1618
}
1719
```

0 commit comments

Comments
 (0)