You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Percentages specify sizing of a box with respect to the box’s <a>containing block</a>.
491
-
When calculating the <a>intrinsic size contribution</a> of the box,
492
-
percentage sizes that would resolve against that box instead behave as ''width/auto''.
493
491
494
492
<div class="example">
495
493
For example, in the following markup:
496
494
497
-
<pre class='lang-html'>
498
-
<div style="width: min-content">
499
-
<div style="width: 50%;">
500
-
LOOOOOOOOOOOOOOOOOOOONG
501
-
</div>
502
-
</div>
503
-
</pre>
504
-
505
-
When calculating the width of the outer div,
506
-
the inner div behaves as ''width: auto'',
507
-
so the outer div sets itself to the width of the long word.
508
-
Since the outer div's width didn't depend on "real" layout,
509
-
though, it's treated as <a>definite</a>
510
-
for resolving the inner div,
511
-
whose width resolves to half that of the outer div.
512
-
</div>
513
-
514
-
Although this may require an additional layout pass to re-resolve percentages in some cases,
515
-
a 'min-width' or 'min-height'
516
-
with a value of ''min-width/min-content'', ''min-width/max-content'', ''min-width/fit-content'',
517
-
or ''min-width/auto'' (or otherwise <a>behaving as auto</a>)
518
-
does not prevent the resolution of percentage sizes of the box’s contents.
495
+
<xmp class='lang-html'>
496
+
<article style="height: 60em">
497
+
<aside style="height: 50%;">
498
+
</aside>
499
+
</article>
500
+
</xmp>
519
501
520
-
In order to prevent cyclic sizing in the general case,
521
-
percentages do not otherwise resolve against <a>indefinite</a> sizes,
522
-
and instead are treated as <css>auto</css>.
502
+
the <code><aside></code> would be 30em tall.
503
+
</div>
523
504
524
-
<div class="issue">
525
-
We think the above paragraphs can be more accurately replaced by:
505
+
Sometimes the size of a percentage-sized box's containing block
506
+
depends on the intrinsic size contribution of the box itself,
507
+
creating a cyclic dependency.
508
+
When calculating the containing block's size,
509
+
the percentage <a>behaves as auto</a>.
510
+
Then, unless otherwise specified,
511
+
when calculating the used sizes and positions of the containing block’s <em>contents</em>:
512
+
513
+
* If the cyclic dependency was introduced due to
514
+
a 'block-size' or 'max-block-size' on the containing block
515
+
that causes it to depend on the size of its contents,
516
+
the box’s percentage is not resolved and instead <a>behaves as auto</a>.
517
+
518
+
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.
519
+
520
+
* Otherwise, the percentage is resolved against the containing block’s size.
521
+
(The containing block’s size is not re-resolved based on the resulting size of the box;
522
+
the contents might thus overflow or underflow the containing block).
523
+
524
+
525
+
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§10.2</a>.
526
+
Note also, the behavior in <a href="https://www.w3.org/TR/CSS2/visudet.html#the-height-property">CSS2§10.5</a>
527
+
is superseded in their respective specifications for layout modes
528
+
(such as <a href="http://www.w3.org/TR/css-flexbox/">flex layout</a>)
529
+
not described in CSS2.
526
530
527
-
<blockquote>
528
-
For the purpose of calculating the <a>intrinsic size contribution</a> of a box,
529
-
an intrinsic 'min-width', 'min-height', or 'inline-size' cause the box's width/height to be treated as indefinite
530
-
(and thus percentages that resolve against it behave as <css>auto</css>).
531
531
532
-
Although this may require an additional layout pass to re-resolve percentages in some cases,
533
-
a 'min-width', 'min-height', or 'inline-size'
534
-
with a value of ''min-width/min-content'', ''min-width/max-content'', ''min-width/fit-content'',
535
-
or ''min-width/auto'' (or otherwise <a>behaving as auto</a>)
536
-
does not prevent the resolution of percentage sizes of the box’s contents.
537
-
</blockquote>
532
+
<div class="example">
533
+
For example, in the following markup:
538
534
539
-
...but we're not 100% sure.
535
+
<xmp class='lang-html'>
536
+
<article style="width: min-content">
537
+
<aside style="width: 50%;">
538
+
LOOOOOOOOOOOOOOOOOOOONG
539
+
</aside>
540
+
</article>
541
+
</xmp>
542
+
543
+
When calculating the width of the outer <code><article></code>,
544
+
the inner <code><aside></code> behaves as ''width: auto'',
545
+
so the <code><article></code> sets itself to the width of the long word.
546
+
Since the <code><article></code>’s width didn't depend on "real" layout,
547
+
though, it's treated as <a>definite</a>
548
+
for resolving the <code><aside></code>,
549
+
whose width resolves to half that of the <code><article></code>.
550
+
</div>
551
+
552
+
<div class="example">
553
+
In this example,
554
+
555
+
<xmp class=lang-html>
556
+
<article style="height:auto">
557
+
<aside style="height: 50%;">
558
+
<div class=block style="height: 150px;"></div>
559
+
</aside>
560
+
<section style="height: 30px;"></section>
561
+
</article>
562
+
</xmp>
563
+
564
+
because the percentage <a>block size</a> ('height', in this case) on block-level elements
565
+
is defined to not resolve inside content-sized containing blocks,
566
+
the percentage height on the <code><aside></code> is ignored,
567
+
that is, it behaves exactly as if ''height/auto'' were specified.
0 commit comments