-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.src.html
5321 lines (4243 loc) · 194 KB
/
Overview.src.html
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
<!doctype html public '-//W3C//DTD HTML 4.01//EN'>
<head profile="
http://microformats.org/profile/h-card
http://microformats.org/profile/hcard
http://microformats.org/profile/rel-license
">
<!-- Note: the h-card profile is for a "microformats 2" vocabulary and
is experimental as of September 2012 -->
<meta content="text/html; charset=utf-8" http-equiv=content-type>
<title>CSS basic box model</title>
<link href="../default.css" rel="stylesheet"
title="Default" type="text/css">
<style type="text/css">
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: */
body {max-width: none}
/* 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>
<link href="https://www.w3.org/StyleSheets/TR/W3C-MO.css" rel="stylesheet"
title="Default" type="text/css">
<link rel=contents href="#contents">
<link rel=index href="#index">
<!--
<pre class=metadata>
Title: CSS basic box model
Shortname: css-box
Level: 3
Status: ED
ED: https://drafts.csswg.org/css-box/
Abstract: <p><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.
Editor: Bert Bos, W3C, mailto:bert@w3.org
Editor: Anton Prowse, Invited Expert, mailto:prowse@moonhenge.net
</pre>
-->
<div class="head">
<!--logo-->
<h1>CSS basic box model</h1>
<h2 class="no-num no-toc">[LONGSTATUS] [DATE: 26 Sep 2006]</h2>
<dl>
<dt>This version:
<dd><a href="[VERSION]"
>[VERSION]</a>
<dt>Latest version:
<dd><a href="https://www.w3.org/TR/css-box-3"
>[LATEST]</a>
<dt>Previous version:
<dd><a href="https://www.w3.org/TR/2007/WD-css3-box-20070809/"
>[PREVIOUS]</a>
<dt>Feedback:</dt>
<dd><a
href="mailto:www-style@w3.org?subject=%5Bcss3-box%5D%20feedback"
>www-style@w3.org</a> with subject line “[css-box-3]
<var>… message topic …</var>” (<a
rel="discussion"
href="http://lists.w3.org/Archives/Public/www-style/"
>archives</a>)
<dt>Editors:
<dd class="h-card vcard"><a class="p-name fn u-url url" rel=author
href="http://www.w3.org/People/Bos/" >Bert Bos</a>, <span
class="p-org org" >W3C</span>, <a class="u-email email"
href="mailto:bert@w3.org" ><bert@w3.org></a>
<dd class="h-card vcard"><span class="p-name fn" >Anton
Prowse</span>, <span class="p-org org" >Invited Expert</span>, <a
class="u-email email" href="mailto:prowse@moonhenge.net"
><prowse@moonhenge.net></a>
</dl>
<!--copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc">Abstract</h2>
<h2 class="no-toc no-num">Status of this document</h2>
<!--status-->
<p>The CSS Working Group plans to ask for W3C Recommendation status
for this specification only when there are sufficiently many
implementations. See the section <a href="#exit">“CR exit criteria”
</a> for details.</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>
<nav id="toc">
<h2 class="no-num no-toc">Table of contents</h2>
<!--toc-->
</nav>
<h2>How to read this specification</h2>
<p>All sections are normative, unless stated otherwise.
<div class=example>
<p>Examples look like this and normally start with the word
“Example.” Examples are not normative.
</div>
<p class=note>Notes look like this and normally start with the word
“Note.” Notes are not normative.
<p class=issue>Editorial notes look like this. They will be removed before
the document becomes Candidate Recommendation.
<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 <em>used value</em> and the
<em>computed value</em> of a property. Unless stated explicitly, the
short form “value” means the computed value.
<h2>Dependencies on other modules</h2>
<p>This CSS module depends on the following other CSS modules:
<ul>
<li><cite>CSS Writing Modes Module</cite> [[!CSS3-WRITING-MODES]]
– switch between vertical and horizontal text, properties
<dfn>writing-mode</dfn> and <dfn>direction</dfn>, definitions of the
terms <dfn>block flow direction</dfn> and <dfn>inline base
direction.</dfn>
<li><cite>CSS Syntax Module</cite> [[!CSS3SYN]] – syntax of
properties and values
<li><cite>CSS Values and Units Module</cite> [[!CSS3VAL]] –
definitions of value types <dfn><var><number></var></dfn>,
<dfn><var><percentage></var></dfn>,
<dfn><var><angle></var></dfn> and
<dfn><var><length></var></dfn>; defines the terms <dfn>computed
value</dfn> and <dfn>used value.</dfn>
<li><cite>CSS Text Module</cite> [[!CSS3TEXT]] – inline layout and
definition of <dfn>line box.</dfn>
<li><cite>CSS Generated and Replaced Content module</cite> [[!CSS3GENCON]]
– defines the terms <dfn>replaced element</dfn>
and <dfn>intrinsic</dfn> size (and intrinsic ratio).
<li><cite>CSS Backgrounds and Borders Module</cite> [[!CSS3BG]] –
defines <dfn><var><bg-position></var></dfn>
<li><cite>CSS Basic User Interface Module</cite> [[!CSS3UI]] –
defines <dfn>box-sizing</dfn>
<li><cite>CSS 2D Transforms</cite> [[!CSS3-2D-TRANSFORMS]] –
defines <dfn>transform</dfn>
<li><cite>CSS Display Module</cite> [[!CSS-DISPLAY-3]] –
defines <dfn>display</dfn>
</ul>
<h2>Introduction & definitions</h2>
<p>Some issues that affect multiple sections in this document:
<div class=issue>
<p>Horizontal centering (more precisely: centering in the inline
direction). The draft contains several suggestions:
<ol>
<li>Setting 'margin' to ''fill''. ''Fill'' is similar to
''auto'', but allowed to be negative:
<pre>P {margin: 1em fill}</pre>
<li>Setting a property 'alignment' on the element to center:
<pre>P {alignment: center}</pre>
<li>Setting a property 'child-align' on the parent of the
element to center:
<pre>DIV {child-align: middle}</pre>
<li>Rely on grid templates [[CSS3LAYOUT]]. You set a template
on the parent or on the element itself. One or the other may
be easier. E.g., to horizontally center the single child of
a <span>horizontal</span> DIV):
<pre>DIV {grid: ". @ ." }</pre>
<p>To horizontally center a P with a template on the P
itself requires that the width of the P isn't set with the
'width' property, but with the 'grid-columns' property (or
the 'grid' shorthand). In the example below the width is
set to 'fit-content':
<pre>P {grid: * fit-content * ". @ ."}</pre>
<p>To vertically center the single child of a
<span>vertical</span> DIV:
<pre>DIV {grid: "@"}
DIV:slot(@) {vertical-align: middle}</pre>
<p>To vertically center a P inside a vertical parent by
means of a template on the P itself requires that the
height of the P isn't set with 'height', but with
'grid-rows' (or the 'grid' shorthand). Below, the height
is set to 10em:
<pre>P {grid: "." *
"@" 10em
"." * }</pre>
<p>See also <a href="/Style/CSS/Tracker/actions/18"
>ACTION-18</a> (especially <a
href="http://lists.w3.org/Archives/Public/www-style/2008May/0045.html"
>the ideas at end of Bert's comment</a> ), which is
continued in <a href="/Style/CSS/Tracker/issues/53"
>ISSUE-53.</a>
</ol>
</div>
<div class=issue id=contain-floats>
<p>Ensuring that the bottom padding (more precisely: the foot
padding) starts after any preceding and descendant floats.
<p>The main use case is to make sure an element is at least as
high as all its floating descendants. I.e., at the end of the
element, clear the floats that are descendants of the
element. That may or may not also clear any floats that were
declared before the element. Some possible approaches:
<ol>
<li>Set 'overflow' to anything else than 'visible' (and
'height' to 'auto'). This requires no new property, but has
the side effect of influencing the scrolling mechanism. It
also doesn't clear any floats that occurred before the
element and doesn't distinguish left, right or other
floats. [2004-02-29 ftf]
<li>A new property 'clear-after'.
<li>Use the value ''shrink-wrap'' (or some other name, e.g.,
''contain'') on 'height' (and 'width', in case of vertical
text) to make an element into a <em>flow root.</em> This
requires no new property, only a new value, but doesn't
clear any floats before the element and doesn't distinguish
left, right or other floats. [The idea to add the
functionality to 'height' is due to IanH 2004-02-29]
<li>The same, but only allow the new keyword on the
'min-height' and 'min-width' properties. [The idea to add
the functionality to 'min-height' is due to Fantasai,
2012-09]
<li>A new value ''container'' on 'display'. This doesn't allow
a ''list-item'' to clear its floats.
</ol>
</div>
<div class=issue>
<p>Vertical centering and alignment (more precisely: in the
block flow direction).
<p>The use cases are centering a single child vertically in its
parent, centering all content of an element vertically (e.g.,
all text on a slide) and aligning only the last child (or the
last <var>n</var> children) against the bottom of the parent.
<p>Possible solutions include:
<ol>
<li>
<p>No new features, just use absolute positioning and
transformations together:
<pre>
.container {
height: 10em; /* Some sufficient height */
position: relative }
.container > * {
margin: 0;
position: absolute;
top: 50%;
transform: translate(0, -50%) }</pre>
<p>(The 'top' moves the top down by half the container's
height, the 'transform' moves the top up by half the
element's own height.) This only works if we are sure the
container is tall enough, because it will not
automatically grow. It only works if there is exactly one
child: it cannot center a sequence of paragraphs in a DIV,
nor the text content of a P.
<li>
<p>No new features, just use flexbox: Set 'display: flex',
'flex-direction: column' and 'justify-content: center' on
the container. This has the side effect of changing both
the container and the children to block boxes, and
inhibiting margin collapsing between the children, so it
isn't suitable to, e.g. vertically center a set of list
items in a UL, or the text content of a P.
<li>Extending 'vertical-align' to apply to block elements:
<pre>DIV {vertical-align: middle}</pre>
<p>This centers or aligns all content, it cannot top-align
the first child and bottom-align the last.
<li>Allowing 'vertical-align' on a new type of box called
''container''. (The main function of ''container'' is to
contain its floating descendants.) This wouldn't allow a
''list-item'', a ''table-caption'' or an 'inline-block'' to
center its content.')
<li>Setting 'margin' to ''fill'':
<pre>P {margin-top: fill}</pre>
<p>This works to center an element in its parent, but not to
center the content of an element with only text.
<li>Relying on grid templates [[CSS3LAYOUT]]. If there are
enough elements, that could work:
<pre>
<STYLE>
BODY {grid: "a . b"} /* 3 columns */
SECTION.a {flow: a; grid: "@" "." "z"} /* 3 rows */
SECTION.b {flow: b; grid: "@" "." "z"} /* 3 rows */
P.note {flow: z}
</STYLE>
<SECTION CLASS=a>
<H1>...</H1>
<P>...
<P CLASS=note>...
</SECTION>
<SECTION CLASS=b>
<H1 ID=b>...</H1>
<P>...
<P CLASS=note>...
</SECTION>
</pre>
<p>And assuming 'vertical-align' applies to slots, then that
also vertically centers the contents of an element. (This
centers horizontally if the element is
<span>vertical,</span> because 'vertical-align' is
relative to the writing mode.)
<pre>P {grid: "@"}
P:slot(@) {vertical-align: center}</pre>
<p>But it is not enough to bottom-align the two paragraphs
with class “note” in this example:
<pre>
<STYLE>
BODY {grid: "a . b"}
H1#a, H1#a ~ P {flow: a}
H1#b, H1#b ~ P {flow: b}
P.note {/* align to bottom?? */}
</STYLE>
<H1 ID=>...</H1>
<P>...
<P CLASS=note>...
<H1 ID=b>...</H1>
<P>...
<P CLASS=note>...
</pre>
<li>
<p>Use centering in the inline direction after switching the
parent to an orthogonal block flow direction. E.g., if the
document is <span>horizontal</span> and we want to
vertically center the single child of a DIV:
<pre>DIV {writing-mode: vertical-rl}
DIV > * {writing-mode: horizontal; width: 100%;
margin-top: auto; margin-bottom: auto}</pre>
<p>This cannot top-align the first child and bottom-align
the second.
<li>
<p>Vertically centering a single element could also be
modeled as a float with an offset. A draft of
[[CSS-PAGE-FLOATS]] from 2013 suggests the following to
center a P vertically inside its parent DIV:
<pre>DIV {height: 15em;
colums: 1} /* Make the DIV act like a "page" */
P {float: top left; /* Place the P in the corner of the DIV... */
float-offset: 0 50%} /* ... and add 50% offset vertically */</pre>
<p>Floats like this also allow to put all children at the
top and the last child against the bottom. But only one
child: trying to push multiple children down to the bottom
results in their order being reversed.
</ol>
</div>
<p class=issue>Investigate if it is possible to make a pseudo-element
to select anonymous boxes ('::paragraph'). See minutes of 10 Aug 2011.
<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 rectangular boxes,
whose size, position, and stacking level on the <em>canvas</em> depend
on their properties. We say that an element <dfn title="generated
box">generates</dfn> one or more boxes. There are numerous different
types of boxes. <span class=issue>[Or maybe only one? I.e., a
block-level box is just a normal box that happens to be generated by a
block-level element?]</span> A block box is like a paragraph; a line
box is like a single line of text; and inline boxes are like words
inside a line.
<div class="issue">
<p>Define the <dfn title="box tree|tree!!of boxes" >box
tree.</dfn> (Is the space
between words a kind of box as well, or a spacer item? Is the current
selection a box? Is there a defined order among sibling boxes? If so,
are bidi inline boxes ordered in reading order or in visual order?)
<p>[Define the box tree before pagination and then describe how
pagination can break one box into two?]
<!--
<ul>
<li>If the parent element is a list item, the boxes go into the
parent's block box, not the marker box.
<li>If the element is run-in, its boxes go either into a box of its
parent element, or into a box of a later sibling.
<li>The order of sibling boxes is always such that boxes that belong
to elements earlier in the document come before boxes of elements that
come later in the document.
<li>Note that 'position' can put a box into the box of an ancestor
(the one establishing the containing block) rather than a parent.
<li>Note that 'flow' puts boxes into a named flow root.
</ul>
-->
</div>
<p>When the specification says a box <var>A</var> <dfn>contains</dfn>
a box <var>B</var> it means <var>B</var> is a child of <var>A</var> in
the <em>box tree.</em> Typically, box <var>B</var> is geometrically
contained within box <var>A</var> as well, but that need not be the
case, because of, e.g., overflow or negative margins.
<p class=note>Note: The precise rules are below and in other modules,
but in summary, <span class=issue>[write something that helps convey
the idea of a flow, e.g.:]</span> a block-level box contains either other
block-level boxes (e.g., a section containing paragraphs, or a table
containing rows), or it contains line boxes (e.g., a paragraph
containing lines of text). A line box contains inline-level boxes
(e.g., a line with words in different styles). An inline-level box may
contain either text interspersed with more inline-level boxes, or it
may contain a block-level box (e.g., a small table that is rendered
inline).
<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 <span
title="generated box">generated</span> directly by the element, or it
is an <em>anonymous box,</em> 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>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>
<p>Properties are set on elements [[!CSS3CASCADE]] and influence how
the element is turned into boxes. Every box has the same properties
with the same values as the element to which it belongs, except for
anonymous boxes: inheritable properties on anonymous boxes have the
same value as the element, while non-inheritable properties have the
initial value. The only property that boxes do not have is the
'display' property. <span class=issue>[Is this useful? Or is it better
to say that boxes are just rectangles with a border, a background, a
position, a bunch of other boxes inside, and a reference to the
element they belong to? They don't really have properties then and it
is only a convenience to say the “the box has a font
<var>X.</var>”</span>
<p>Boxes do not have specified values [[!CSS3CASCADE]], but they do
have computed, used and actual values.
<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
<em>block-level box,</em> <em>block container box</em> and <em>table
box</em> 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>
<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'
<th>'writing-mode: vertical-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.” More information about 'writing-mode'
and 'direction' can be found in [[!CSS3-WRITING-MODES]].
</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.”
<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'' <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'' <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 class=note>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>''vertical-lr'' <td>height <td>width
</table>
<p>These correspond to the dimensions in the <em>inline base
direction</em> and the <em>block flow direction,</em> 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 class=note>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.
<p>When boxes are laid out to form a <em class=index
>flow</em> (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>A edge,</dfn> <dfn>B edge,</dfn> <dfn>C edge</dfn> and <dfn>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><em>containing block</em>
<th>'direction' of<br><em>containing block</em>
<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'' <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'' <th>''rtl''
<td>left <td>bottom <td>right <td>top
<tr><!-- vertical-lr --><th>''ltr''
<td>left <td>top <td>right <td>bottom
</table>
<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., <em>horizontal</em> 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
<em>vertical</em> element with a <em>horizontal</em> <em>containing
block</em> or a <em>horizontal</em> element with a <em>vertical</em>
<em>containing block.</em> An <dfn>orthogonal flow</dfn> is a
<em>flow</em> whose <em>flow root</em> is an orthogonal element.
<h2>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 <em>initial
containing block</em>).
<p>When the viewport is smaller than the area of the <em>canvas</em>
(see below) on which the document is rendered, the user agent usually
offer 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=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
[[CSS3LAYOUT]], 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 <em>initial containing block</em> 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 <em title="block container box" >block container boxes</em>
(defined below) can be flow roots. (Which implies that the children of
a flow root are laid out in a <em>block formatting context.</em>)
<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 <span>vertical</span> and its parent is
<span>horizontal.</span> <span class=issue>[Add link to the relevant
section.]</span>
<li>The box is <span>horizontal</span> and its parent is
<span>vertical.</span>
<!-- <li>The value of 'transform' is not 'none'. -->
<li>The value of 'child-align' is not 'auto'. <span class=issue>[If
'child-align' is adopted, rather than, say, 'margin: fill']</span>
</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 [[CSS3LAYOUT]] 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 <em>flow root</em>
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>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.