Skip to content

Commit 15faddb

Browse files
committed
[css-sizing-4] Rewrite the 'stretch-fit sizing' section to match WG resolution. #11044
1 parent f170bb8 commit 15faddb

File tree

1 file changed

+65
-50
lines changed

1 file changed

+65
-50
lines changed

css-sizing-4/Overview.bs

Lines changed: 65 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -836,65 +836,80 @@ Stretch-fit Sizing: filling the containing block</h3>
836836
to make its outer size as close to filling the [=containing block=] as possible
837837
while still respecting the constraints imposed by min-height/min-width/max-height/max-width.
838838

839-
Formally, its behavior is the same as specifying an [=automatic size=]
840-
together with a [=self-alignment property=] value of ''width/stretch''
841-
(in the relevant axis),
842-
except that the resulting box,
843-
which can end up not exactly fitting its [=alignment container=],
844-
can be subsequently aligned by its actual [=self-alignment property=] value.
845-
846-
Additionally,
847-
in [=formatting contexts=] and axes in which the relevant [=self-alignment property=] does not apply
848-
(such as the block axis in Block Layout, or the main axis in Flex Layout),
849-
in cases where a percentage size in that axis would resolve to a definite value,
850-
a [=stretch-fit size=]
851-
causes the box to attempt to fill its containing block--
852-
behaving as ''100%''
853-
but applying the resulting size to its margin box
854-
instead of the box indicated by 'box-sizing'.
855-
For this purpose, ''margin/auto'' margins are treated as zero,
856-
and furthermore, for [=block-level boxes=] in particular,
857-
if its block-start/block-end [=margin=]
858-
would be adjoining to its parent's block-start/block-end [=margin=]
859-
if its parent’s [=sizing properties=] all had their [=initial values=],
860-
then its block-start/block-end [=margin=] is treated as zero.
861-
862-
Note: Consequently, if neither ''align-self/stretch'' alignment applies
863-
nor percentage sizing can resolve,
864-
then the box will resolve to its [=automatic size=].
839+
: If used in an axis where the relevant [=self-alignment property=] applies to the element
840+
::
841+
Produces the same size that would be obtained
842+
by the [=self-alignment property=] in that axis
843+
being set to ''justify-self/stretch''
844+
and all [=sizing properties=] and 'aspect-ratio'
845+
being set to their initial values.
846+
847+
: Otherwise, if used in an axis where percentage sizes can resolve to a [=definite=] value
848+
::
849+
Behaves as ''100%'',
850+
except it sizes the [=margin box=]
851+
regardless of the value of 'box-sizing'.
852+
853+
If this is a [=block axis=] size,
854+
and the element is in a Block Layout [=formatting context=],
855+
and the parent element does not have a [=block-start=] 'border' or 'padding'
856+
and is not an [=independent formatting context=],
857+
treat the element's [=block-start=] margin as zero
858+
for the purpose of calculating this size.
859+
Do the same for the [=block-end=] margin.
860+
861+
Note: This simulates the effect of margins collapsing with the parent's margin.
862+
It doesn't actually suppress the margins,
863+
so if anything prevents the element from actually collapsing with its parent,
864+
the [=stretch-fit size=] might actually be too large
865+
to fit in the parent perfectly.
866+
867+
<!--
868+
Importantly, this *does* ensure that the stretch-fit size
869+
doesn't depend on the presence or absence of other elements,
870+
or the element's position among its siblings.
871+
Multiple children with 'stretch' will all end up the same size.
872+
-->
873+
874+
: Otherwise
875+
::
876+
Behaves as the property's [=initial value=].
865877

866878
<div class="example">
867879
For example, given the following HTML representing two [=block boxes=]:
868-
<pre class=html>
869-
&lt;div class="outer">
870-
&lt;div class="inner">&lt;/div>
871-
&lt;/div>
872-
</pre>
880+
881+
<xmp class=html>
882+
<div class="parent">
883+
<div class="child">text</div>
884+
</div>
885+
</xmp>
873886

874887
In the following case,
875-
the [=outer height=] of the inner box
876-
will exactly match the height of the outer box (200px),
888+
the [=outer height=] of the child box
889+
will exactly match the height of the parent box (200px),
877890
but its [=inner height=] will be 20px less, to account for its margins.
878891

879892
<pre>
880-
.outer { height: 200px; border: solid; }
881-
.inner { height: stretch; margin: 10px; }
893+
.parent { height: 200px; border: solid; }
894+
.child { height: stretch; margin: 10px; }
882895
</pre>
883896

884-
In the following case,
885-
the height of the inner box
886-
will exactly match the height of the outer box (200px).
887-
The top margins will collapse,
888-
but the bottom margins do not collapse
889-
(because the bottom margin of a box is not adjoining
890-
to the bottom margin of a parent with a non-''height/auto'' height,
891-
see [[CSS2/box#collapsing-margins]]),
892-
and therefore the inner box’s bottom margin will be truncated.
897+
On the other hand,
898+
in this case we can assume that the child's margins will collapse with the parent,
899+
so the inner box will be ''200px'' tall,
900+
exactly filling the parent.
893901

894902
<pre>
895903
.outer { height: 200px; margin: 0; }
896904
.inner { height: stretch; margin: 10px; }
897905
</pre>
906+
907+
(The top margins will in fact collapse,
908+
but the bottom margins do not collapse,
909+
because the bottom margin of a box is not adjoining
910+
to the bottom margin of a parent with a non-''height/auto'' height,
911+
see [[CSS2/box#collapsing-margins]].
912+
Luckily, an overflowing bottom margin doesn't have any visible effect.)
898913
</div>
899914

900915
<div class="example">
@@ -903,15 +918,15 @@ Stretch-fit Sizing: filling the containing block</h3>
903918
(due to the 10px margin):
904919

905920
<pre class=html>
906-
&lt;div class="outer">
907-
&lt;div class="inner">text&lt;/div>
921+
&lt;div class="parent">
922+
&lt;div class="child">text&lt;/div>
908923
&lt;/div>
909924
some more text
910925
</pre>
911926

912927
<pre>
913-
.outer { float: left; margin: 0; }
914-
.inner { width: stretch; margin: 10px; }
928+
.parent { float: left; margin: 0; }
929+
.child { width: stretch; margin: 10px; }
915930
</pre>
916931
</div>
917932

@@ -922,8 +937,8 @@ Stretch-fit Sizing: filling the containing block</h3>
922937
so ''height: stretch'' [=behaves as auto=] as well.
923938

924939
<pre>
925-
.outer { height: auto; margin: 0; }
926-
.inner { height: stretch; margin: 10px; }
940+
.parent { height: auto; margin: 0; }
941+
.child { height: stretch; margin: 10px; }
927942
</pre>
928943
</div>
929944

0 commit comments

Comments
 (0)