Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the fr unit in a CSS Windows 8 metro style application mean?

Looking at the following CSS in a Windows 8 metro style application, what is "fr"?

-ms-grid-columns: 638px 1fr; 
like image 820
Paul Mendoza Avatar asked Mar 10 '12 21:03

Paul Mendoza


People also ask

What is Fr in CSS unit?

Thankfully, CSS Grid Layout introduces a new unit of length called fr, which is short for “fraction”. MDN defines the fr unit as a unit which represents a fraction of the available space in the grid container.

What does 1FR mean?

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.

What is 2fr in HTML?

</ body > </ html > output 2. We have 4 columns, the first two columns take up the same amount of space i.e. 1fr and the last two columns take up the same amount of space i.e. 2fr.


2 Answers

Pertaining to your exact question, for this particular example, let's assume that the total available width for the columns is 1200px. Since the first column width is fixed, it will occupy 638px and the remaining space (562px) will be free. Thus, in this case,

1fr = 562px

Now let's assume your styling is as follows:-

-ms-grid-columns: 638px 1fr 2fr; 

Then in this case, the remaining free space of 562px will be divided in three parts and the second column will be given 1/3rd space and the third column will be given 2/3rd space.

like image 120
Gaurang Avatar answered Sep 21 '22 09:09

Gaurang


It stands for "fraction" or "fractional unit", a proposed unit in CSS Level 3.

From https://www.w3.org/TR/css3-grid-layout/#fr-unit:

Fraction values are new units applicable to the grid-rows and grid-columns properties... The distribution of fractional space occurs after all or content-based row and column sizes have reached their maximum. The total size of the rows or columns is then subtracted from the available space and the remainder is divided proportionately among the fractional rows and columns.

From http://msdn.microsoft.com/en-us/library/windows/apps/hh780610.aspx:

...fractional unit (1FR)... represents one share of all the space available to the grid after fixed-size and auto-sized tracks (rows or columns) are laid out.

Also, from http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/95fddeb2-04bc-4f2b-bfb6-ffecffe5e8d5/:

1fr is one "fractional unit", which is a way of saying "the remaining space in the element".

like image 38
Luke Girvin Avatar answered Sep 19 '22 09:09

Luke Girvin