Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does minmax(0, 1fr) work for long elements while 1fr doesn't?

Tags:

css

css-grid

So I have this grid:

+---------+------------------------------+---------+     |  <div>  |  <p> - 1000 characters long  |  <div>  | +---------+------------------------------+---------+ 

Inside p there's super long string with no spaces. divs are placeholders with fixed dimensions. This produces the above:

  display: grid;   grid-auto-flow: column;   grid-template-columns: auto minmax(0, 1fr) auto; 

But changing minmax(0, 1fr) to 1fr gives this:

+---------+----------------------------------------+     |  <div>  |               <p> - 1000 characters long  |  <div>  | +---------+----------------------------------------+ 

It overflows out of its parent and way out of screen size. Why isn't it behaving like minmax?

Codepen

like image 585
seeker_of_bacon Avatar asked Oct 17 '18 18:10

seeker_of_bacon


People also ask

How does Minmax function work?

The minmax() CSS function defines a size range greater than or equal to min and less than or equal to max. It is used with CSS Grids.

What is 1fr?

What's a fraction (1FR)? A fraction or 1FR is one part of the whole. 1 fraction is 100% of the available space. 2 fractions are 50% each. So, 1FR is 1/2 of the available space.


1 Answers

Because 1fr is equivalent to minmax(auto, 1fr), by default.

When you use minmax(0, 1fr), that's something different than standalone 1fr.

In the first case, the track cannot be smaller than the size of the grid item (min size is auto).

In the second case, the track is free to resize to a 0 width/height.

More details:

  • Reconsider the meaning of 1fr
  • Prevent grid area from expanding causing whole page to scroll
like image 179
Michael Benjamin Avatar answered Sep 30 '22 20:09

Michael Benjamin