-
Notifications
You must be signed in to change notification settings - Fork 707
/
Copy pathblock-layout.bs
4362 lines (3540 loc) · 165 KB
/
block-layout.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!-- TODO: cross-references aren't automatically generated by
Bikeshed. Is there a better way than to add <a> around every
<span> and <em>? -->
<!-- TODO: bibliography still doesn't show the dated specs. -->
<pre class=metadata>
Title: CSS Basic Box Model Level 3
Shortname: css3-box
Level: none
Status: ED
Work Status: rewriting
Previous version: https://www.w3.org/TR/2018/WD-css3-box-20180731/
TR: https://www.w3.org/TR/css3-box/
ED: https://drafts.csswg.org/css-box-3/
Group: csswg
Editor: Bert Bos, W3C, mailto:bert@w3.org, w3cid 3343
Editor: Anton Prowse, Invited Expert, mailto:prowse@moonhenge.net, w3cid 48426
Markup Shorthands: markdown no, markup yes
Abstract:
<abbr title="Cascading Style Sheets">CSS</abbr> describes the
rendering of documents on various media. When textual documents (e.g.,
HTML) are laid out on visual media (e.g., screen or print), CSS models
their layout as a collection of rectangular boxes containing words, lines,
paragraphs, tables, etc., each with properties such as size, color and
font.
<p>This module describes the basic types of boxes: block, list item,
inline, etc.; and some of their properties, including margins, padding
and width/height. It defines a layout called a “flow,” in which a
series of boxes is laid out one after the other, and it defines
“floating” boxes. Other kinds of layout, such as tables, absolute
positioning, ruby annotations, grid layouts, columns and page boxes,
are described by other modules. Also, the layout of text inside a line
(including the handling of left-to-right and right-to-left scripts) is
defined elsewhere.
<p>In CSS level 3, boxes may contain either horizontal or vertical text.
Different orientations can be mixed.
Status Text:
<![CDATA[<p> <div> <input id=annoying-warning type=checkbox title="hide
warning"> <label for=annoying-warning>(hide)</label> <div> <p>This
draft is undergoing changes and many parts are not consistent with
other modules of CSS. <p>Please, refer to CSS level 2 [[!CSS21]]
instead for the definition of the basic box model. </div> </div>
<p>This module should eventually replace corresponding parts of the
revised CSS level 2 specification [[!CSS21]]. But this is an early
draft and any differences to level 2 are most likely unintentional,
unless they concern new features, such as vertical text or float
displacement. <em>Please help us improve the next draft by pointing
out such differences.</em>
]]>
</pre>
<pre class=link-defaults>
spec:css-display-3; type:value; for:display; text:block
spec:css-display-3; type:value; for:display; text:list-item
spec:css-display-3; type:value; for:display; text:table
</pre>
<style>
ol.stack p {margin-top: 0}
img.small {max-width: 100%}
.minidiagram {height: 6em; vertical-align: middle}
dt {display: inline}
dt + dt::before {content: ", "}
/* Undo the max-width in the 2012 style for editor's drafts: */
/* maybe replace this with using default.css's class=data? */
.equiv-table {margin: 0.5em 0; border-collapse: collapse;
border-bottom: hidden; empty-cells: show}
.equiv-table th, .equiv-table td {padding: 0.3em 1em;
border-bottom: thin solid #666}
.equiv-table th {text-align: left}
/* .equiv-table th:first-child {text-align: right} */
.equiv-table caption {margin: 0.5em 0 0 0}
.equiv-table td > p:first-child, .equiv-table th > p:first-child {
margin-top: 0}
.equiv-table tr {vertical-align: baseline}
.equiv-table img {max-width: 100%}
/* The TR postprocessor already inserted quotes: */
.css::before, .property::before, .descriptor::before {content: none}
.css::after, .property::after, .descriptor::after {content: none}
@media screen {
#annoying-warning:not(:checked) + * + * {position: fixed; z-index: 2;
bottom: 2em; left: 0; right: 0; text-align: center;
padding: 0.5em 0.5em 1em 0.5em; box-shadow: 0 2px 8px black;
border-top: thin solid; border-bottom: thin solid;
background: hsla(40,100%,50%,0.9); color: black}
#annoying-warning:not(:checked) + * + * p {margin: 0}
#annoying-warning, #annoying-warning + * {position: fixed; z-index: 3}
#annoying-warning {font-size: 1em; bottom: 2.3em; right: 0.5em; margin: 0}
#annoying-warning + * {font-size: 80%; bottom: 2.5em; right: 2.3em}
#annoying-warning:checked, #annoying-warning:checked + * {display: none}
html {margin-bottom: 15em}
}
</style>
<!--=================================================================-->
<!--
<p>Each property is defined in part in the text and in part by a table
that groups together a number of facts about the property, including a
regular expression to restrict its syntax. See <span
class=issue>[where?]</span> for the meaning. The “Inherited” and
“Initial” rows in the table are used by the Cascading and Inheritance
module [[CSS3CASCADE]] and “Media” by the Media Queries specification
[[MEDIAQ]].
<p>The specification may refer to the <a>used value</a> and the
<a>computed value</a> of a property. Unless stated explicitly, the
short form “value” means the computed value.
-->
<!--=================================================================-->
<h2 id=dependencies>Dependencies on other modules</h2>
<p>This CSS module depends on the following other CSS modules:
<p class=issue>To do…
<!--=================================================================-->
<h2 id=intro>Introduction & definitions</h2>
<div class=issue id=center-text>
<p>How to center the text of a block element horizontally (more
precisely: in the inline direction) even if (part of) the block is
next to a float?
</div>
<div class=issue id=center-block>
<p>How to center a block horizontally in its CB if the block is wider
than the CB? (I.e., when 'margin: auto' doesn't work and the document
structure doesn't allow transforms or flexbox.)
</div>
<div class=issue id=distribute>
<p>How to center or distribute blocks vertically when flexbox doesn't
apply (e.g., because the blocks aren't siblings)?
</div>
<div class=issue id=anonymous-box-pseudo>
<p>Investigate if it is possible to make a pseudo-element to select
anonymous boxes ('::paragraph'). See minutes of 10 Aug 2011.
</div>
<p class=note>Note: The model in this specification differs from the
model described in the CSS level 2 specification [[!CSS21]], because
it is generalized to apply also to vertical text. A document using
only features from level 2 renders exactly as described there, except
possibly for features that are undefined in that specification and
have become defined since.
<p>CSS assumes that the document to lay out is modeled as a <span
class=index title="tree!!of elements|document tree|element
tree">tree</span> of <dfn title="element">elements.</dfn> Each element
has an ordered list of zero or more child elements, with an optional
string of text before the list, in-between the children and after the
list. Each child has one parent, except for the unique element that
has no parent, which is called the <dfn>root element.</dfn>
<p class=note>Note that such a tree can be described in XML or SGML,
but also in other notations and that it is the definition of that
notation, not CSS, that determines the equivalence between the
abstract tree and the concrete notation. E.g., SGML often allows white
space to be added between elements for readability, which does not
result in a string of spaces in the abstract tree.
<p>CSS describes how each element and each string of text is laid out
by transforming the document tree into a set of boxes, whose size,
position, and stacking level on the <a>canvas</a> depend on their
properties. We say that an element <dfn title="generated
box">generates</dfn> one or more boxes.
<div class=issue id=box-tree>
<p>Define the box tree <!-- Is it a tree (possibly with cross-links)?
A graph? Purely geometrical? Or are boxes not linked to each other,
but only to elements or viewports? When we say box A contains box B,
does that mean B is geometrically within A, or just that B's
generating element is a descendant of A's generating element? Is there
only one kind of box or are there several (line box, block box, margin
box…)? E.g., if we talk about an “inline box”, is that a kind of box,
or only a shorthand for “a box generated by an inline element”? Are
letters (glyphs) boxes? Are words? Is the space between words a box or
a margin? Or does that depend on the white-space property? Is there an
order defined for boxes? E.g., can we talk about the “first” or the
“next” box? About the “first box of a fragmentainer”? The “first box
of an element”? Does bidi-reordering, flexbox reordering, run-in
reordering or absolute positioning change that order? -->
</div>
<div class=figure>
<p><img src="box-intro.png" alt="Each generated box in the rendering
has a link to the element that generated it.">
<p class="caption">Relation between four displayed boxes in the
rendered document (on the right) and the three corresponding elements
in the source document on the (left).
</div>
<div class=example>
<p>For example, a fragment of HTML such as
<pre><ul>
<li>The first item in the list.
<li>The second item.
</ul></pre>
<p>may result in <span class=issue>[rewrite the following
sentence?]</span> one block-level box for the <code>ul</code> element,
containing two block-level boxes for the two <code>li</code> elements,
each of which has one line box (i.e., one line of text). Both line
boxes contain two inline-level boxes: one that contains the list
bullet and one that contains the text.
<p>Note how the <code>li</code> is transformed into multiple boxes, including
one that contains “generated content,” viz., the list bullet,
which is not present in the source document.
<p>If the document is rendered in a narrow window, it may be that the
<code>li</code> elements get transformed into even more boxes, because the
text requires multiple lines. And if the document is rendered on paper
or in multiple columns, it
may be that a page break falls in the middle of the <code>ul</code> element,
so that it is not transformed into a single block-level box, but into two
smaller ones, each on a different page or column.
</div>
<p>Each box belongs to exactly one element. It is either <a
title="generated box">generated</a> directly by the element, or it
is an <a>anonymous box,</a> which has been inserted to ensure that
every box and its parent are of mutually compatible types as defined
by the layout rules of CSS. An anonymous box is defined to belong to
whichever element generates the box's closest element-generated
ancestor box. When we need to be precise, we say that the anonymous
box is <dfn title="induce">induced,</dfn> rather than generated, by
the element it belongs to.
<p class=note>For example, an anonymous table wrapper box that is
created around a table cell because the table cell element doesn't
have a table element as parent, belongs to the parent element of the
table cell, not to the table cell itself.
<p class=note>An anonymous box is never a <em>principal</em>
box. Except for that, an anonymous box cannot be distinguished by its
property values and characteristics from a box generated by some
hypothetical document element. <span class=issue>Remove this note? Do
we actually use the concept of “principal box” anywhere?</span>
<div class=issue>
<p>Do boxes have properties? Or do they just have margins, borders,
padding, a size and some content (which may be text in a certain font
and a certain color, but without the box itself having a font or a
color property)?
</div>
<!--
<p class=note>Boxes are frequently referred to by their property
values. For example, a “floated box” is a box whose computed value of
'float' is not ''none'', and a “positioned box” is a box whose
computed value of 'position' is not ''static''. However, terms such as
<a>block-level box,</a> <a>block container box</a> and <a>table
box</a> describe characteristics which cannot be deduced solely from
a box's property values.
-->
<div class=figure id=various>
<p><img src="box.png" alt="Diagram of a typical box, showing the
content, padding, border and margin areas">
<p class="caption">The various areas and edges of a typical box
</div>
<p>Boxes have padding, a border and margins (see
the <a href="#various">figure</a>). Different properties determine the
thickness of each of these (which may be zero). The margins of
adjacent boxes are also subject
to <em title="collapse">collapsing</em> (i.e., the actual margin
between adjacent boxes may be less than the sum of the boxes'
individual margins).
<p>Each box has a <dfn>content area</dfn> (a.k.a. <dfn>content
box</dfn>). The rectangle that bounds this area is the <dfn>content
edge.</dfn> Around the content area is the <dfn>padding area</dfn> and
its outside bounds are called the <dfn>padding edge</dfn>. The padding
area and content area together form the <dfn>padding box</dfn>.
Outside the padding is the <dfn>border area</dfn> and the outside
boundary of that area is the <dfn>border edge</dfn>/ The border area,
padding area and content area together form the <dfn>border box</dfn>.
Finally, outside the border is the <dfn>margin area</dfn> and its
outer edge is the <dfn>margin edge</dfn>.
<p>When the specification says that the padding or border is
<dfn title="absent|padding!!absent|border!!absent" >“absent”</dfn>
on some side of the box, that means that
its thickness is zero.
<p><em title="line box">Line boxes</em> cannot have any padding,
border or margin, and therefore their margin edge, border edge,
padding edge and content edge all coincide.
<p class=note>Note that the margin, unlike the border and padding, may have
a negative thickness. That is one way to make adjacent boxes overlap each
other.
<p class=note>Note that the edges always form rectangles, even if
there is a 'border-radius' [[CSS3BG]] or a shape [[CSS3-EXCLUSIONS]].
<p>We say that a box or element is <dfn>horizontal</dfn> if its
'writing-mode' property is ''horizontal-tb'', otherwise it is
<dfn>vertical</dfn> (see [[!CSS3-WRITING-MODES]]).
<!--
<div class=note>
<p>Note that there are theoretically eight possible orientations for
text, but CSS only defines six:
<table class=equiv-table style="table-layout: fixed; width: 100%">
<thead>
<tr>
<th style="width: 8em">
<th>'writing-mode: horizontal-tb'
<th>'writing-mode: vertical-rl' or 'writing-mode: sideways-rl'
<th>'writing-mode: vertical-lr' or 'writing-mode: sideways-lr'
<tbody>
<tr>
<th>'direction: ltr'
<td>
<p>Text is written from left to right and paragraphs
grow downwards <p><img class=small
src="horizontal.png" alt="">
<td>
<p>Text is written top to bottom and paragraphs grow to
the left <p><img class=small src="vertical.png"
alt="">
<td>
<p>Text is written top to bottom and paragraphs grow to
the right <p><img class=small src="vertical-lr.png"
alt="">
<tr>
<th>'direction: rtl'
<td>
<p>Text is written from right to left and paragraphs
grow downwards <p><img class=small
src="horizontal-rtl.png" alt="">
<td>
<p>Text is written bottom to top and paragraphs grow to
the left <p><img class=small src="vertical-rtl.png"
alt="">
<td>
<p>Text is written bottom to top and paragraphs grow to
the right <p><img class=small
src="vertical-lr-rtl.png" alt="">
</table>
<p>There is no “horizontal-bt.”
</div>
-->
<p class=mtb>Calculations of the size and position of boxes are
usually very similar for horizontal and vertical boxes, except that
the horizontal and vertical directions are interchanged. To avoid many
almost identical definitions, this specification therefore often uses
abstract terms instead of top, right, bottom, left, width and height:
four terms (block-start, block-end, inline-start and inline-end) for
the four edges of a box, four terms (A edge, B edge, C edge and D
edge) for the edges of the children of a box and two terms (measure
and extent) for the width and height of a box.
<p class=note>XSL-FO [[XSL11]] uses “inline-progression dimension” for
“measure” and “block-progression dimension” for “extent.”
<div class=note>
<p>The following terms are defined in [[!CSS3-WRITING-MODES]]. For
convenience, here is a short summary.
<p>The <dfn>block-start</dfn>, <dfn>block-end</dfn>, <dfn>inline-start</dfn> and
<dfn>inline-end</dfn> edge of a box refer to the top, right, bottom
and left edges, depending on the 'writing-mode' and 'direction'
properties of that box, as follows:
<table class=equiv-table>
<thead>
<tr>
<th>'writing-mode'
<th>'direction'
<th>“block-start”
<th>“inline-end”
<th>“block-end”
<th>“inline-start”
<th>Diagram
<tbody>
<tr><th rowspan=2>''horizontal-tb'' <th>''ltr'' <td>top
<td>right <td>bottom <td>left <td><img class=minidiagram
src="box-tb-ltr.svg" alt="">
<tr><!--horizontal-tb--> <th>''rtl'' <td>top <td>left
<td>bottom <td>right <td><img class=minidiagram
src="box-tb-rtl.svg" alt="">
<tr><th rowspan=2>''vertical-rl'', ''sideways-rl'' <th>''ltr'' <td>right
<td>bottom <td>left <td>top <td><img class=minidiagram
src="box-rl-ltr.svg" alt="">
<tr><!--vertical-rl--> <th>''rtl'' <td>right <td>top
<td>left <td>bottom <td><img class=minidiagram
src="box-rl-rtl.svg" alt="">
<tr><th rowspan=2>''vertical-lr'', ''sideways-lr'' <th>''ltr'' <td>left
<td>bottom <td>right <td>top <td><img class=minidiagram
src="box-lr-ltr.svg" alt="">
<tr><!--vertical-lr--> <th>''rtl'' <td>left <td>top <td>right
<td>bottom <td><img class=minidiagram src="box-lr-rtl.svg"
alt="">
</table>
<p>For example, the “block-start padding” by default refers
to the 'padding-top' and the “inline-end border” is by default the
'border-right'.
<p>Similarly, the specification sometimes refers to the
<dfn>measure</dfn> and <dfn>extent</dfn> of a box, instead of width
and height, as follows:
<table class=equiv-table>
<tr>
<th>'Writing-mode'
<th>“measure”
<th>“extent”
<tr><td>''horizontal-tb'' <td>width <td>height
<tr><td>''vertical-rl'' <td>height <td>width
<tr><td>''sideways-rl'' <td>height <td>width
<tr><td>''vertical-lr'' <td>height <td>width
<tr><td>''sideways-lr'' <td>height <td>width
</table>
<p>These correspond to the dimensions in the <a>inline base
direction</a> and the <a>block flow direction,</a> respectively.
<p>An alternative term for the measure is
<dfn title="logical width|width!!logical">logical width</dfn>
and an alternative term for extent is
<dfn title="logical height|height!!logical">logical height</dfn>.
These terms occasionally occur in other CSS modules.
<p>The extent of a box is thus the distance between the
block-start and block-end edges, while the measure of the box is the
distance between the inline-start and inline-end edges.
</div>
<p>When boxes are laid out to form a <a class=index >flow</a> (see
below), their edges play different roles in the alignment of the boxes
within that flow. The orientation of the flow determines which edge of
a box is aligned to which edge of another box. These roles are
independent of the orientation of the box itself. We distinguish four
roles for the edges of a box, called <dfn lt="A|A edge">A
edge</dfn>, <dfn lt="B|B edge">B edge</dfn>, <dfn lt="C|C edge">C
edge</dfn> and <dfn lt="D|D edge">D edge</dfn>. They depend on the
'writing-mode' and 'direction' properties of the box's
<em class=index>containing block</em> (defined below), and map to the four sides as
follows:
<table class=equiv-table>
<thead>
<tr>
<th>'writing-mode' of<br><a>containing block</a>
<th>'direction' of<br><a>containing block</a>
<th>“A edge”
<th>“B edge”
<th>“C edge”
<th>“D edge”
<tbody>
<tr><th rowspan=2>''horizontal-tb'' <th>''ltr''
<td>top <td>right <td>bottom <td>left
<tr><!-- horizontal-tb --><th>''rtl''
<td>top <td>left <td>bottom <td>right
<tr><th rowspan=2>''vertical-rl'', ''sideways-rl'' <th>''ltr''
<td>right <td>bottom <td>left <td>top
<tr><!-- vertical-rl --><th>''rtl''
<td>right <td>top <td>left <td>bottom
<tr><th rowspan=2>''vertical-lr'', ''sideways-lr'' <th>''rtl''
<td>left <td>bottom <td>right <td>top
<tr><!-- vertical-lr --><th>''ltr''
<td>left <td>top <td>right <td>bottom
</table>
<div class=figure>
<p><img src="abcd-edges" alt="Image: A box with edges labeled
clockwise from top as A, B, C and D.">
<p class=caption>The edges of a box whose containing block is
horizontal.
</div>
<p class=note>For example, block-level boxes in a flow are laid out
such that the A edge of the first box is against the block-start edge
of the containing block and then the A edge of each subsequent box is
put against the C edge of its predecessor. For typical English text
(i.e., <a>horizontal</a> text), this means the top edge (= A edge)
of the first paragraph is at the top edge (= block-start) of the
document, the top (A edge) of the second paragraph is against the
bottom (C edge) of the first paragraph, and so on, until the bottom (C
edge) of the last paragraph becomes the bottom (block-end) of the
document.
<p>An element is called <dfn>orthogonal</dfn> if it is either a
<a>vertical</a> element with a <a>horizontal</a> <a>containing
block</a> or a <a>horizontal</a> element with a <a>vertical</a>
<a>containing block.</a> An <dfn>orthogonal flow</dfn> is a
<a>flow</a> whose <a>flow root</a> is an orthogonal element.
<!--=================================================================-->
<h2 id=viewport>The viewport and the canvas</h2>
<p>User agents for continuous media generally offer users a
<dfn>viewport</dfn> (a window or other viewing area on the screen)
through which users consult a document. User agents may change the
document's layout when the viewport is resized (see the <a>initial
containing block</a>).
<p>When the viewport is smaller than the area of the <a>canvas</a>
(see below) on which the document is rendered, the user agent usually
offers a scrolling mechanism. There is at most one viewport per canvas,
but user agents may render to more than one canvas (i.e., provide
different views of the same document).
<p>For all media, the term <dfn>canvas</dfn> describes the space where
the formatting structure is rendered. The canvas is infinite for each
dimension of the space.
<!--=================================================================-->
<h2 id=cb>Containing blocks</h2>
<p>The <dfn>containing block</dfn> of a box is a rectangle that
is associated with the box and that is used in various definitions in this
specification. Apart from a size and a position, the rectangle also has
'direction' and 'writing-mode' properties. The containing block of a box
is defined as follows:
<ul>
<li>The containing block of the <a title="root element">root
element's</a> top-level boxes is a rectangle with the dimensions of
the <a>viewport</a>, anchored at the <a>canvas's</a>
origin for continuous media and the page area for paged media. (See
[[MEDIAQ]] and [[CSS3PAGE]] for definitions of continuous and paged
media.) This containing block is called the <dfn>initial containing
block.</dfn> The 'direction' and 'writing-mode' of the initial
containing block are the same as those of the root element.
<li>For other elements, the containing block is one of the
following:
<ol>
<li>If the element is a ''run-in'' that is rendered
inline in a sibling element, then its containing block
is the <a>content edge</a> of the <a>principal
box</a> of that sibling.
<li>Otherwise, if the parent has a <a>principal
box</a> that is a <a>block container box</a>
(e.g., if the parent is a 'table-cell' or a 'block'),
then the containing block is the content edge of the
parent's <a>principal box.</a>
<li>Otherwise the containing block is the same as that
of the parent.
</ol>
</ul>
<p class=issue>Other modules may introduce other types of boxes with
other rules for how to find their containing block. E.g., the
containing block of an absolutely positioned element.
<p>In the above, a <dfn>block container box</dfn> is, informally, a
box that can contain block boxes. More precisely: any box generated by
a (pseudo-)element with a computed value for 'display' of ''block'',
''inline-block'', ''table-caption'', ''table-cell'' or ''list-item''.
<span class=note>Note that most floating and absolutely
positioned elements have a computed 'display' of ''block''. Also, a
<a>flow root</a> has a computed 'display' of ''block''.</span>
<span class=issue>Or insert the definition of block container box from
CSS 2.1 here?</span>
<p class=issue>Also define <dfn>principal box</dfn> somewhere.
<p class=note>Note that the above is modified by the Absolute Positioning
module [[CSS3POS]]: in particular, if a box's 'position' property is neither
''static'' nor ''relative'', its containing block is established
differently.
<p>If an element <span class=issue>[or a viewport?]</span> has
scrollbars (see 'overflow'), then any space taken up by the scrollbars
should be excluded from (subtracted from the dimensions of) any
containing block formed by that element.
<!--=================================================================-->
<h2 id=flows>Flows</h2>
<p>The <dfn>flow</dfn> (sometimes called <dfn>normal flow</dfn>) is
one of the two basic kinds of layout in CSS, together with line layout
[[CSS3LINE]]. It can be used, e.g., to layout a sequence of
paragraphs, headings, lists and floated elements in a single
column. Other CSS modules, such as tables [[CSS3TBL]], positioning
[[CSS3POS]], flex boxes [[CSS3-FLEXBOX]] and grid templates
[[CSS-TEMPLATE-3]], build on the flow model by defining ways to split a
document into more than one flow and positioning and aligning those
flows in various ways on the canvas.
<p>A flow is constructed starting from a <span class=index title="flow
root!!box" >box</span> called the <dfn>flow root</dfn> by the <a
href="#construct-flow">rules below.</a> We say the flow is
<dfn>channeled</dfn> by the flow root.
<p class=issue>Are there more intuitive names than flow root?
<p>The <dfn title="initial flow|flow!!initial" >initial flow</dfn> is
the flow that contains the root of the box tree.
<p>Despite not being a box, the <a>initial containing block</a> is
said to be the flow root of the initial flow.
<p class=issue id=pagination-issue>How do we model pagination? If a
flow is broken over two pages or columns, do we call it a single flow
or two flows? I.e., is the page box the flow root of the flow, or is
the page box something else, more like the viewport, which influences
the layout of a flow but isn't part of it? See [[CSS3-BREAK]].
<p>Only <a>block container boxes</a> (defined below) can be flow
roots. (Which implies that the children of a flow root are laid out in
a <a>block formatting context.</a>)
<p>Several (combinations of) properties cause an element to generate
boxes that are flow roots. This module defines a few. Other modules
may define more.
<div class=note>
<p>For example, this module defines that any of the following make a
box into a flow root:
<ul>
<li>The value of 'float' is not 'none'.
<li>The used value of 'overflow' is not 'visible'.
<!-- <li>The box is a table wrapper, a table cell, an inline block, or an
align box. -->
<!-- <li>The value of 'position' is 'absolute' or 'fixed' (see
[[CSS3POS]]). -->
<li>The box is <a>vertical</a> and its parent is
<a>horizontal.</a> <span class=issue>[Add link to the relevant
section.]</span>
<li>The box is <a>horizontal</a> and its parent is
<a>vertical.</a>
<!-- <li>The value of 'transform' is not 'none'. -->
</ul>
<p>Other examples: The table layout module [[CSS3TBL]] defines that a
table cell generates a box that is a flow root; the positioning module
[[CSS3POS]] defines that an absolutely positioned element generates a
flow root; the grid template module [[CSS-TEMPLATE-3]] defines that a
template element generate several flow roots; and the transforms
module [[CSS3-TRANSFORMS]] defines that an element with a transform
generates a flow root.
</div>
<p class=mtb id=construct-flow>The flow of a given <a>flow root</a>
is a set of boxes. A box belongs to the flow if all of the following
are true:
<ol>
<li>The used value of 'display' is ''block'', ''list-item'',
''table'' or ''flex''.
<li>The used value of 'float' is ''none''.
<li>The used value of 'position' is ''static'' or ''relative''.
<li>The used value of 'flow-into' [[CSS3-REGIONS]] <span
class=issue>a.k.a. 'flow' [[CSS-TEMPLATE-3]]</span> is ''none''.
<li>It is not a <a>flex item</a> [[!CSS3-FLEXBOX]].
<li>It is either a child of the flow root or a child of a box that
belongs to the flow.
</ol>
<p class=note>Note that the flow root is itself not part of the flow
it channels and that each flow root channels at most one flow.
<p class=note>Note that the last rule above implies that a flow with
its flow root together are always a connected subset of the box
tree. In other words; together, they form a subtree of the box tree
with possibly some branches removed.
<p class=note>Note that the element tree and the box tree are not
necessarily parallel: the element a box belongs to need not be the
child of the element that generated the box's parent. E.g., run-in
elements may generate boxes that become children of boxes from sibling
elements; and the 'flow' property [[CSS-TEMPLATE-3]] and the 'position'
property [[CSS3POS]] may cause an element to generate a box that
becomes the child of a box from a grandparent or other ancestor
element. E.g., 'DIV {flow: b}' (see [[CSS-TEMPLATE-3]]) makes the DIV
generate boxes that become children of the box generated by slot b in
some ancestor. And 'DIV {position: absolute}' causes the DIV to
generate a box that becomes a child of the box generated by the
ancestor that established the DIV's <a>containing block.</a>
<div class=example>
<p>For example, the fragment
<pre>
<div class=sidebar>
<p>Text in a sidebar.
<p>Here is quote:
<blockquote lang=ja>
<p>...
</blockquote>
<p>Etc. etc.
</div>
</pre>
<p>with the style
<pre>
div.sidebar { writing-mode: horizontal-tb; float: left }
blockquote[lang|=ja] { writing-mode: vertical-rl; height: 10em }
</pre>
<p>defines two flows:
<ol>
<li>The <code>div</code> is a flow root, because it floats. Its flow
consist of the 1st, 2nd and 4th <code>p</code> and the
<code>blockquote</code>.
<li>The <code>blockquote</code> is an <a>orthogonal</a> element
(in this case a <a>vertical</a> box inside a <a>horizontal</a>
parent) and it is thus a flow root. Its flow is formed by the 3rd
<code>p</code>.
</ol>
<p>(The <code>div</code> itself belongs to a third flow, but its flow
root is not shown in the fragment.)
</div>
<p class=note>Note that a flow root is not necessarily block-level, it may
be an ''inline-block'', e.g.
<p class=note>Note that a box belongs to at most one flow. (Some boxes
do not belong to any flow, because they are part of a different kind of
layout, such as table layout.)
<p>An element that generates a flow root box is itself also called a
<span class=index title="flow root!!element">flow root.</span>
<p class=note>Note: The terminology in the CSS level 2 specification
is different. A flow root is called “an element that establishes a
<span class=index title="formatting context|new formatting
context">new formatting context.</span>”
<p class=note>A consequence of this terminology is that an
<em>element,</em> unlike a box, can be the flow root of several
flows. E.g., template elements [[CSS-TEMPLATE-3]] generate several flow
root boxes. Depending on what properties are set on a list item and on
its marker pseudo-element, a list item can also generate zero, one or
two flow roots.
<!--=================================================================-->
<h2 id=boxes>Types of boxes</h2>
<p>The layout of boxes in the flow is in large part determined by the
interplay of the 'display' properties of an element and its parent,
and then fine-tuned with margins and padding.
<!-- The value ''compact'' is missing in [[!CSS-DISPLAY-3]]. -->
<h3 id=block-level-cb-flows>Block-level boxes, containing blocks
and anonymous boxes</h3>
<p>A <dfn>block-level</dfn> box is a box that has a <a>computed
value</a> for 'display' of ''block'', <!--''container'',--> ''list-item'',
''table'', ''table-*'' (i.e., all table boxes, see [[CSS3TBL]]),
''run-in'' (under
certain circumstances), or ''compact'' (under certain circumstances).
<p>An <dfn>inline-level</dfn> box is a box that has a <a>computed
value</a> for 'display' of ''inline'', ''inline-block'',
''inline-table'', ''ruby'', ''run-in'' (under certain circumstances),
or ''compact'' (under certain circumstances).
<p class=issue>[What about the other ruby values?]
<p>An <dfn>anonymous box,</dfn> informally, is a box that cannot be addressed
with CSS selectors. All its properties, except for 'display', have their
default values (either the initial value or inherited). Anonymous boxes are
created when the CSS box model requires a child box with a certain value for
'display', but the child actually has a different value. In that case an
anonymous box of the right kind is created and wraps the child (or children).
<p>This module defines one kind of anonymous box:
<p>A <a>block-level box</a> may contain either <a>line boxes</a> or
<a>block-level</a> boxes, but not both. If necessary, any line boxes
that belong to this box's element are wrapped in one or more (as few
as possible) anonymous boxes with a 'display' of ''block''.
<p>Other modules (e.g., [[CSS3TBL]], [[!CSS3TEXT]]) may also define
anonymous boxes.
<div class=example>
<p>An example of anonymous boxes is this document fragment:
<pre><p>Somebody whose name I have
forgotten, said, long ago: <q>a box is
a box,</q> and he probably meant it.</p></pre>
<p>with these style rules:
<pre>p { display: block }
q { display: block; margin: 1em }</pre>
<p>The <code>p</code> element has both line boxes and a child box for the
<code>q</code> element, which is a block-level element. The line boxes before
the <code>q</code> are wrapped in an anonymous block-level box and so are the
line boxes after the <code>q</code>. The resulting tree of boxes might be as
follows (refer to the <a href="#When">figure</a>):
<ul>
<li>block-level box [p]
<ul>
<li>block-level box [anonymous]
<ul>
<li>line box: “Somebody…”
<li>line box: “forgotten…”
</ul>
<li>block-level box [q]
<ul>
<li>line box: “a box…”
</ul>
<li>block-level box [anonymous]
<ul>
<li>line box: “and he…”
</ul>
</ul>
</ul>
<div class=figure id=When>
<p><img alt="The P element has two line boxes before the q and one
after. The first two are wrapped in an anonymous box, the last one
is wrapped in another anonymous box." src="anonymous.png">
<p class="caption">When the fragment is rendered, the text before
the q is wrapped in an anonymous block and the text after the q in
another.
</div>
</div><!--example-->
<p class=note>Note that the anonymous boxes defined in this module are
<a>block-level,</a> but anonymous boxes defined in other
modules may be different.
<h3 id=compact-boxes>Compact boxes</h3>
<p>A compact box is a box that is either put in the margin of the next
box or becomes a block of its own, depending on whether it is small
enough to fit in the margin or not. The typical use case is for lists
where most labels are small enough to fit in the margin, except for a
few.
<div class=example>
<p>An example is the DL list in HTML. Its COMPACT attribute indicates
to the formatter that the labels of the list are good candidates for
display as compact boxes:
<pre>
<h3>Farm animals</h3>
<dl compact>
<dt>cat
<dd>Lorem ipsum dolor sit amet, consectetaur adipisicing elit…
<dt>dog
<dd>Ut enim ad minim veniam, quis nostrud exercitation…
<dt>hippopotamus
<dd>Duis aute irure dolor in reprehenderit in voluptate velit…
<dt>fly
<dd>Excepteur sint occaecat cupidatat non proident, sunt in…
</dl>
</pre>
<p>With a style rule like
<pre>dl[compact] dt {display: compact}</pre>
<p>this might be rendered as in the figure below.
<div class=figure>
<p><img src="compact" alt="[sample rendering]" style="max-width: 24em">
<p class=caption>Three of the four labels are narrow enough to fit
in the left margin. The one that is too wide is converted into a
block.
</div>
</div>
<p class=issue>Add definition.
<!--
<p>Whether a compact box <var>X</var> is displayed as a block or in
the margin is determined as follows. Let <var>Y</var> be the next
sibling element in document order in the same flow as <var>X</var>, if
any. Let <var>W</var> be the hypothetical distance between the <a
title="D edge" >D</a> and <a title="B edge" >B</a> margin edges of
<var>X</var> if the 'display' property of <var>X</var> were set to
''block'' and any ''auto'' on its measure were replaced by
''fit-content''.
<ul>
<li>If there is no such <var>Y</var>, then <var>X</var> is displayed
as a block.
<li>If <var>Y</var> has a 'display' of ''list-item'', then
<var>X</var> is displayed as a block.
<li>If <var>Y</var> is not <em>block-level</em>, then <var>X</var> is
displayed as a block.
<li>If the <a title="D edge" >D</a> margin of Y is less than
<var>W</var>, then <var>X</var> is displayed as a block.
<li>Otherwise, <var>X</var> is displayed in that margin.
</ul>
<p class=issue>Also look at the padding of <var>Y</p>? I.e., check if
the sum of the padding, border and margin is wide enough?
<p>If <var>X</var> is displayed as a block, it is a
<a>block-level</a> element and it is sized and positioned exactly as
if its 'display' had been ''block''.
<p>Otherwise, <var>X</var> is placed such that its
<a title="D edge">D</a> margin edge aligns with the <a>inline-start</a> margin edge of
its <a>containing block</a> and its <a title="A edge" >A</a> border
edge aligns with the <a title="A edge" >A</a> border edge of
<var>Y</var>. It is in this case an <a>inline-level</a> element.
<p class=issue>Do we do anything to avoid that floats overlap with
<var>X</var>? Do we do anything if <var>X</var> is taller than
<var>Y</var>? E.g., adjust the 'min-height' of <var>Y</var>?
<div class=example>
<p>Simple example...
</div>
<div class=example>
<p>This example shows a compact box that has a different <em>writing
mode</em> than its containing block:
<pre>
dl {writing-mode: horizontal-tb; direction: ltr}
dd {margin-left: 3em}
dt {display: compact; writing-mode: vertical-rl}
...
<dl>
<dt>cat
<dd>Lorem ipsum dolor sit amet, consectetaur adipisicing elit…
</dl>
</pre>
<p>The margin that is considered is the left margin of the DD, because
the containing block (established by the DL) is
top-to-bottom/left-to-right. That margin is thus compared to the width
of the DT and it is large enough, which leads to a rendering similar
to the figure below.
<div class=figure>
<p><img src="compact-vert" alt="[Sample rendering]" style="max-width: 24em">
<p class=caption>The word “cat” written sideways fits to
the left of the definition.
</div>
</div>
-->
<h3 id=mixing>Mixing the box model with other formatting models</h3>
<p>There may be documents that combine different layout models, such
as documents that combine HTML (typically rendered with the CSS box
model) and <span class=index>SVG</span> (rendered with its own
graphics model).
<p class=issue>Do we need one or more 'display' values to signal that
an element is not to be formatted with CSS?
<p>An element that is not rendered according to the CSS box model is
treated as a <em>replaced element</em> for the purposes of determining