|
2 | 2 | title: Grid layout
|
3 | 3 | description: Equal sized items in a responsive grid
|
4 | 4 | author: xshubhamg
|
| 5 | +contributors: tryoxiss |
5 | 6 | tags: layout,grid
|
6 | 7 | ---
|
7 | 8 |
|
8 | 9 | ```css
|
9 | 10 | .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)); |
12 | 13 | /* Explanation:
|
13 | 14 | - `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. |
15 | 17 | */
|
16 | 18 | }
|
17 | 19 | ```
|
0 commit comments