Skip to content

Commit cfdc4a2

Browse files
committed
[css-grid-1][css-flexbox-1] Add explanation of flex values <1. Fixes #2617.
1 parent 8a46204 commit cfdc4a2

File tree

2 files changed

+89
-12
lines changed

2 files changed

+89
-12
lines changed

css-flexbox-1/Overview.bs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,45 @@ The 'flex' Shorthand</h3>
15251525
when positive free space is distributed.
15261526
When omitted, it is set to ''1''.
15271527

1528+
<details class=note>
1529+
<summary>Flex values between 0 and 1 have a somewhat special behavior:
1530+
when the sum of the flex values on the line is less than 1,
1531+
they will take up less than 100% of the free space.</summary>
1532+
1533+
An item’s 'flex-grow' value
1534+
is effectively a request for some proportion of the free space,
1535+
with ''1'' meaning “100% of the free space”;
1536+
then if the items on the line are requesting more than 100% in total,
1537+
the requests are rebalanced to keep the same ratio but use up exactly 100% of it.
1538+
However, if the items request <em>less</em> than the full amount
1539+
(such as three items that are each ''flex-grow: .25'')
1540+
then they'll each get exactly what they request
1541+
(25% of the free space to each,
1542+
with the final 25% left unfilled).
1543+
See [[#resolve-flexible-lengths]] for the exact details
1544+
of how free space is distributed.
1545+
1546+
This pattern is required for continuous behavior as 'flex-grow' approaches zero
1547+
(which means the item wants <em>none</em> of the free space).
1548+
Without this, a ''flex-grow: 1'' item would take all of the free space;
1549+
but so would a ''flex-grow: 0.1'' item,
1550+
and a ''flex-grow: 0.01'' item,
1551+
etc.,
1552+
until finally the value is small enough to underflow to zero
1553+
and the item suddenly takes up none of the free space.
1554+
With this behavior,
1555+
the item instead gradually takes less of the free space
1556+
as 'flex-grow' shrinks below ''1'',
1557+
smoothly transitioning to taking none of the free space at zero.
1558+
1559+
Unless this “partial fill” behavior is <em>specifically</em> what's desired,
1560+
authors should stick to values &ge; 1;
1561+
for example, using ''1'' and ''2'' is usually better
1562+
than using ''.33'' and ''.67'',
1563+
as they're more likely to behave as intended
1564+
if items are added, removed, or line-wrapped.
1565+
</details>
1566+
15281567
<dt><dfn><<'flex-shrink'>></dfn>
15291568
<dd>
15301569
This <<number>> component sets 'flex-shrink' <a href="#flex-components">longhand</a>

css-grid-1/Overview.bs

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,13 @@ Explicit Track Sizing: the 'grid-template-rows' and 'grid-template-columns' prop
14401440
<dd>
14411441
A non-negative dimension with the unit ''fr'' specifying the track's <dfn dfn noexport>flex factor</dfn>.
14421442
Each <<flex>>-sized track takes a share of the remaining space in proportion to its <a>flex factor</a>.
1443-
See <a href="#fr-unit">Flexible Lengths</a> for more details.
1443+
For example, given a track listing of ''1fr 2fr'',
1444+
the tracks will take up ⅓ and ⅔ of the <a>leftover space</a>, respectively.
1445+
See [[#fr-unit]] for more details.
1446+
1447+
Note: If the sum of the <a>flex factors</a> is less than 1,
1448+
they'll take up only a corresponding fraction of the <a>leftover space</a>,
1449+
rather than expanding to fill the entire thing.
14441450

14451451
When appearing outside a ''minmax()'' notation,
14461452
implies an automatic minimum (i.e. ''minmax(auto, <<flex>>)'').
@@ -1719,25 +1725,53 @@ Flexible Lengths: the ''fr'' unit</h4>
17191725
which represents a fraction of the <a>leftover space</a> in the <a>grid container</a>.
17201726
Tracks sized with ''fr'' units are called <dfn>flexible tracks</dfn>
17211727
as they flex in response to <a>leftover space</a>
1722-
similar to how <a>flex items</a> fill space in a <a>flex container</a>.
1723-
1724-
Note: <<flex>> values are not <<length>>s
1725-
(nor are they compatible with <<length>>s, like some <<percentage>> values),
1726-
so they cannot be represented in or combined with other unit types in ''calc()'' expressions.
1728+
similar to how <a>flex items</a> with a zero base size fill space in a <a>flex container</a>.
17271729

17281730
The distribution of <a>leftover space</a> occurs after all non-flexible <a>track sizing functions</a> have reached their maximum.
17291731
The total size of such rows or columns is subtracted from the available space, yielding the <a>leftover space</a>,
17301732
which is then divided among the flex-sized rows and columns in proportion to their <a>flex factor</a>.
17311733

1732-
Note: Flexible lengths in a <a>track list</a> work similarly to flexible lengths with a zero base size in [[CSS-FLEXBOX-1]].
1733-
17341734
Each column or row's share of the <a>leftover space</a> can be computed as the column or row's
17351735
<code>&lt;flex> * &lt;leftover space> / &lt;sum of all <a>flex factors</a>&gt;</code>.
17361736

1737-
Note: If the sum of the <a>flex factors</a> is less than 1,
1738-
they'll take up only a corresponding fraction of the <a>leftover space</a>,
1739-
rather than expanding to fill the entire thing.
1740-
This is similar to how Flexbox [[CSS-FLEXBOX-1]] acts when the sum of the 'flex' values is less than 1.
1737+
<details class=note>
1738+
<summary><<flex>> values between 0fr and 1fr have a somewhat special behavior:
1739+
when the sum of the flex factors is less than 1,
1740+
they will take up less than 100% of the leftover space.</summary>
1741+
1742+
A track’s <<flex>> value
1743+
is effectively a request for some proportion of the leftover space,
1744+
with ''1fr'' meaning “100% of the leftover space”;
1745+
then if the tracks in that axis are requesting more than 100% in total,
1746+
the requests are rebalanced to keep the same ratio but use up exactly 100% of it.
1747+
However, if the tracks request <em>less</em> than the full amount
1748+
(such as three tracks that are each ''.25fr'')
1749+
then they'll each get exactly what they request
1750+
(25% of the leftover space to each,
1751+
with the final 25% left unfilled).
1752+
See [[#algo-flex-tracks]] for the exact details
1753+
of how leftover space is distributed.
1754+
1755+
This pattern is required for continuous behavior as ''fr'' values approach zero
1756+
(which means the tracks wants <em>none</em> of the leftover space).
1757+
Without this, a ''1fr'' track would take all of the leftover space;
1758+
but so would a ''0.1fr'' track,
1759+
and a ''0.01fr'' track,
1760+
etc.,
1761+
until finally the value is small enough to underflow to zero
1762+
and the track suddenly takes up none of the leftover space.
1763+
With this behavior,
1764+
the track instead gradually takes less of the leftover space
1765+
as its flex factor shrinks below ''1fr'',
1766+
smoothly transitioning to taking none of the leftover space at zero.
1767+
1768+
Unless this “partial fill” behavior is <em>specifically</em> what's desired,
1769+
authors should stick to values &ge; 1;
1770+
for example, using ''1fr'' and ''2fr'' is usually better
1771+
than using ''.33fr'' and ''.67fr'',
1772+
as they're more likely to behave as intended
1773+
if tracks are added or removed.
1774+
</details>
17411775

17421776
When the available space is infinite
17431777
(which happens when the <a>grid container</a>’s width or height is <a>indefinite</a>),
@@ -1749,6 +1783,10 @@ Flexible Lengths: the ''fr'' unit</h4>
17491783
The maximum of those is used as the resolved ''1fr'' length (the <dfn>flex fraction</dfn>),
17501784
which is then multiplied by each <a>grid track</a>’s <a>flex factor</a> to determine its final size.
17511785

1786+
Note: <<flex>> values are not <<length>>s
1787+
(nor are they compatible with <<length>>s, like some <<percentage>> values),
1788+
so they cannot be represented in or combined with other unit types in ''calc()'' expressions.
1789+
17521790
<!--
17531791
████████ ████████ ██████ ███████ ██ ██ ██ ████████ ████████
17541792
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██

0 commit comments

Comments
 (0)