Skip to content

Commit d2d72c5

Browse files
committed
[css-sizing-3] Fix up percentage sizing per WG resolution--zero out margins/paddings/min-width/min-height. w3c#2384 w3c#2297
1 parent 49d847c commit d2d72c5

File tree

1 file changed

+61
-44
lines changed

1 file changed

+61
-44
lines changed

css-sizing-3/Overview.bs

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -841,41 +841,13 @@ Intrinsic Contributions</h3>
841841
that contains only that box,
842842
if that hypothetical float's containing block is zero-sized/infinitely-sized.
843843

844-
If the box is [=non-replaced=],
845-
then the value of any [=sizing property=] specified on it
846-
as an expression containing a percentage
847-
(such as ''10%'' or ''calc(10px + 0%)'')
848-
is treated <em>for the purpose of calculating the box’s intrinsic size contribution only</em>
849-
as that property’s initial value.
850-
For example, given a box with ''width: calc(20px + 50%)'',
851-
its max-content contribution is calculated as if its 'width' were ''width/auto''.
852-
The percentage is honored as usual, however, during the actual sizing of the box itself.
853-
854-
However, in the case of a [=replaced element|replaced=] box with a percentage-based 'width'/'max-width'/'height'/'max-height',
855-
the percentage is resolved to zero
856-
when calculating the <a>min-content contribution</a> in the corresponding axis.
857-
(See [[#min-content-zero]] for a list of which elements in HTML this applies to.)
858-
The UA may additionally floor this size based on UI considerations,
859-
such as ensuring certain UI elements remain visible
860-
(for example, the dropdown arrow on a <{select}>).
861-
862-
<div class=example>
863-
For example,
864-
an <{input}> assigned ''width: calc(50% + 50px)''
865-
has a <a>min-content contribution</a> of ''50px'',
866-
plus any horizontal margin/border/padding.
867-
</div>
868-
869-
Note: We are not 100% sure if zeroing out a percentage 'max-width' on form controls is web-compatible.
870-
See <a href="https://github.com/w3c/csswg-drafts/issues/765">Issue 765</a>.
871-
872-
Note: This specification does not define how to determine these sizes.
844+
Note: This specification does not define precisely how to determine these sizes.
873845
Please refer to [[CSS2]],
874846
the relevant CSS specification for that display type,
847+
the <a href="#percentage-sizing">rules for handling percentages</a> (below),
875848
and/or existing implementations
876849
for further details.
877850

878-
879851
<!--
880852
████████ ██ ██ ████████ ████████ ████ ██ ██ ██████ ████ ██████
881853
██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██
@@ -912,11 +884,58 @@ Extrinsic Size Determination</h2>
912884
the <code>&lt;aside></code> would be 30em tall.
913885
</div>
914886

915-
Sometimes the size of a percentage-sized box's containing block
887+
Sometimes the size of a percentage-sized box’s <a>containing block</a>
916888
depends on the intrinsic size contribution of the box itself,
917889
creating a cyclic dependency.
918-
When calculating the containing block's size,
919-
the percentage <a>behaves as auto</a>.
890+
When calculating the <a>intrinsic size contribution</a> of such a box,
891+
a <dfn>cyclic percentage</dfn>--
892+
that is,
893+
a percentage value that would resolve against a containing block size
894+
which itself depends on that percentage--
895+
is resolved specially:
896+
897+
898+
* If the box is [=non-replaced=],
899+
then the entire value of any
900+
[=max size property=] or [=preferred size property=]
901+
('width'/'max-width'/'height'/'max-height')
902+
specified as an expression containing a percentage
903+
(such as ''10%'' or ''calc(10px + 0%)'')
904+
that is <a lt="cyclic percentage">cyclic</a>
905+
is treated
906+
<em>for the purpose of calculating the box’s intrinsic size contribution only</em>
907+
as that property’s [=initial value=].
908+
For example, given a box with ''width: calc(20px + 50%)'',
909+
its max-content contribution is calculated as if its 'width' were ''width/auto''.
910+
(The percentage is honored as usual, however,
911+
during the actual sizing of the box itself; see below.)
912+
913+
* If the box is [=replaced element|replaced=],
914+
a <a>cyclic percentage</a> in the value of any
915+
[=max size property=] or [=preferred size property=]
916+
('width'/'max-width'/'height'/'max-height'),
917+
is resolved against zero
918+
when calculating the <a>min-content contribution</a> in the corresponding axis.
919+
(See [[#min-content-zero]] for a list of which elements in HTML this applies to.)
920+
The UA may additionally floor this size based on UI considerations,
921+
such as ensuring certain UI elements remain visible
922+
(for example, the dropdown arrow on a <{select}>).
923+
924+
<div class=example>
925+
For example,
926+
an <{input}> assigned ''width: calc(50% + 50px)''
927+
has a <a>min-content contribution</a> of ''50px'',
928+
plus any horizontal margin/border/padding.
929+
</div>
930+
931+
Note: We are not 100% sure if zeroing out a percentage 'max-width' on form controls is web-compatible.
932+
See <a href="https://github.com/w3c/csswg-drafts/issues/765">Issue 765</a>.
933+
934+
* For the [=min size properties=],
935+
as well as for margins and paddings,
936+
a <a>cyclic percentage</a> is resolved against zero
937+
for determining the intrinsic size contribution.
938+
920939
Then, unless otherwise specified,
921940
when calculating the used sizes and positions of the containing block’s <em>contents</em>:
922941

@@ -925,26 +944,23 @@ Extrinsic Size Determination</h2>
925944
that causes it to depend on the size of its contents,
926945
the box’s percentage is not resolved and instead <a>behaves as auto</a>.
927946

928-
Note: <a href="https://www.w3.org/TR/css-grid/">Grid containers</a> (<a href="https://github.com/w3c/csswg-drafts/issues/1679">and flex items?</a>) do allow percentages to resolve in this case.
947+
Note: <a>Grid items</a> and <a>flex items</a>
948+
do allow percentages to resolve in this case.
929949

930950
* Otherwise, the percentage is resolved against the containing block’s size.
931951
(The containing block’s size is not re-resolved based on the resulting size of the box;
932952
the contents might thus overflow or underflow the containing block).
933953

934-
Note: These rules specify the previously-undefined behavior of this cyclic case in <a href="https://www.w3.org/TR/CSS2/visudet.html#the-width-property">CSS2&sect;10.2</a>.
954+
Note: These rules specify the previously-undefined behavior of this cyclic case
955+
in <a href="https://www.w3.org/TR/CSS2/visudet.html#the-width-property">CSS2&sect;10.2</a>,
956+
<a href="https://www.w3.org/TR/CSS2/box.html#margin-properties">CSS2&sect;8.3</a>,
957+
and
958+
<a href="https://www.w3.org/TR/CSS2/box.padding-properties">CSS2&sect;8.4</a>.
935959
Note also, the behavior in <a href="https://www.w3.org/TR/CSS2/visudet.html#the-height-property">CSS2&sect;10.5</a>
936960
is superseded in their respective specifications for layout modes
937961
(such as <a href="http://www.w3.org/TR/css-flexbox/">flex layout</a>)
938962
not described in CSS2.
939963

940-
Similarly, percentage margins and padding behave as zero in such cyclic cases
941-
when calculating the containing block's size,
942-
and then resolve when calculating the used sizes and positions of its content.
943-
(This defines the previously-undefined behavior of this cyclic case in
944-
<a href="https://www.w3.org/TR/CSS2/box.html#margin-properties">CSS2&sect;8.3</a>
945-
and
946-
<a href="https://www.w3.org/TR/CSS2/box.padding-properties">CSS2&sect;8.4</a>.
947-
948964
<div class="example">
949965
For example, in the following markup:
950966

@@ -984,7 +1000,8 @@ Extrinsic Size Determination</h2>
9841000
</div>
9851001

9861002
<div class=example>
987-
Issue: Letting %s still resolve against a definite 'height'
1003+
1004+
Issue: Letting percentages still resolve against a definite 'height'
9881005
when the min-height is intrinsic is an open issue.
9891006
(CSS2 has a general statement about "height depending on contents",
9901007
which this technically is,

0 commit comments

Comments
 (0)