Question:
I have a grid with 2 columns x 2 rows. All of them are set inminmax()
size. Can I ask why the element with class show
doesn’t take the full size of the grid even though I set all other elements (hide
class) in the grid to width 0 and height 0. Doesn’t minmax()
work properly?Answer:
Theminmax()
function is working fine. So is the calc()
function.The problem is a misunderstanding about the minimum height and widths that are set.
Even though you set the grid items to zero width and height:
.show
from expanding across the entire container.Consider using
auto
instead of minmax()
in grid-template-*
. That will enable the column / row to track the size of the grid item.Also consider the solutions in these posts:
- How to make a column span full width when a second column is not there? (CSS Grid)
- Is it possible to hide columns with empty content via the grid-template-columns definition?
- minmax() defaulting to max
If you have better answer, please add a comment about this, thank you!