-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathOverview.src.html
More file actions
5337 lines (4240 loc) · 195 KB
/
Overview.src.html
File metadata and controls
5337 lines (4240 loc) · 195 KB
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
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://www.w3.org/2006/03/hcard
http://microformats.org/wiki/rel-license">
<meta content="text/html; charset=utf-8" http-equiv=content-type>
<title>CSS basic box model</title>
<style type="text/css">
ol.stack p {margin-top: 0}
img.small {max-width: 100%}
</style>
<link rel=contents href="#contents">
<link rel=index href="#index">
<link href="../default.css" rel="stylesheet"
title="Default" type="text/css">
<link href="http://www.w3.org/StyleSheets/TR/W3C-MO.css" rel="stylesheet"
title="Default" type="text/css">
<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]">
http://www.w3.org/TR/[YEAR]/ED-css3-box-[CDATE]</a>
<dt>Latest version:
<dd><a href="http://www.w3.org/TR/css3-box">
http://www.w3.org/TR/css3-box</a>
<dt>Previous version:
<dd><a href="http://www.w3.org/TR/2002/WD-css3-box-20021024">
http://www.w3.org/TR/2002/WD-css3-box-20021024</a>
<dt>Editors:
<dd class=vcard><span class=fn>Bert Bos</span> (<span
class=org>W3C</span>) <span class=email>bert@w3.org</span>
</dl>
<!--copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc">Abstract</h2>
<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.
<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 class=mtb>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>
<h2 class="no-num no-toc">Table of contents</h2>
<!--toc-->
<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
A3CA
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>
</ul>
<h2>Introduction & definitions</h2>
<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.
<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>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 <em>block-level</em>
boxes, <em title="line box">line boxes</em> and <em
title="inline-level">inline-level boxes.</em> A block-level box is
like a paragraph. A line box is like a line of text. Inline-level
boxes are like words inside a line.
<p>When the specification says a box <var>A</var> <dfn>contains</dfn>
a box <var>B</var>, then <var>B</var> is a box generated by an element
that is a descendant of the element that generated
<var>A</var>. Typically, box <var>B</var> is geometrically
contained in 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, 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="Schematic representation of rel">
<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 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, 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.
</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> (defined below), which is inserted
because the layout rules of CSS require a box to contain a certain
kind of other box, but the boxes generated by the child elements are
not of that kind. The anonymous box is defined to belong to the
parent.
<p class=note>Note: This is mainly important for <span
class=index>WYSIWYG document editors</span>: if the user selects a box
on the screen in order to set a property, the editor knows which
element to set the property on.
<p>Properties are set on elements and influence how the element is turned
into boxes, but in this specification we refer interchangeably to “the
<var>P</var> property of an element” and “the <var>P</var>
property of a box” (both of which actually mean “<em>the
value</em> of property <var>P</var> of…”), unless it is
important to distinguish the box and the element, e.g., because the element
has several boxes and they don't all have the same value for the property.
<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 are also
subject to <em title="collapse">collapsing.</em>
<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
“absent” on some side of the box, that actually 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>A box or element is <dfn>horizontal</dfn> if its 'writing-mode'
property is ''horizontal-tb'', otherwise it is <dfn>vertical.</dfn>
The <dfn>orientation</dfn> of a box or element is the pair of values
of its 'writing-mode' and 'direction'
<div class=note>
<p>Note that there are theoretically eight possible orientations, but
CSS only defines six:
<table class=equiv-table>
<thead>
<tr>
<th>
<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-rl.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
<td>
<p>Text is written bottom to top and paragraphs grow to
the left
<td>
<p>Text is written bottom to top and paragraphs grow to
the right
</table>
<p>There is no “horizontal-bt.”
</div>
<p>This specification sometimes refers to abstract edges
<dfn>head,</dfn> <dfn>end,</dfn> <dfn>tail</dfn> and <dfn>start,</dfn>
which are relative to the orientation of a box. They map to top,
right, bottom and left as follows:
<table class=equiv-table>
<thead>
<tr>
<th>Value of 'writing-mode'
<th>Value of 'direction'
<th>Meaning of “head”
<th>Meaning of “end”
<th>Meaning of “tail”
<th>Meaning of “start”
<tbody>
<tr><th>''horizontal-tb'' <th>''ltr''
<td>top <td>right <td>bottom <td>left
<tr><th>''horizontal-tb'' <th>''rtl''
<td>top <td>left <td>bottom <td>right
<tr><th>''vertical-rl'' <th>''ltr''
<td>right <td>bottom <td>left <td>top
<tr><th>''vertical-rl'' <th>''rtl''
<td>right <td>top <td>left <td>bottom
<tr><th>''vertical-lr'' <th>''rtl''
<td>left <td>bottom <td>right <td>top
<tr><th>''vertical-lr'' <th>''ltr''
<td>left <td>top <td>right <td>bottom
</table>
<p>For example, the “head padding” by default refers to the
'padding-top' and the “end border” is by default the 'border-right'.
<div class=issue>
<p>[Alternative terminology:]
<p>This specification sometimes refers to abstract edges
<dfn>A,</dfn> <dfn>B,</dfn> <dfn>C</dfn> and <dfn>D,</dfn>
which are relative to the orientation of a box. They map to top,
right, bottom and left as follows:
<table class=equiv-table>
<thead>
<tr>
<th>Value of 'writing-mode'
<th>Value of 'direction'
<th>Meaning of “A”
<th>Meaning of “B”
<th>Meaning of “C”
<th>Meaning of “D”
<tbody>
<tr><th>''horizontal-tb'' <th>''ltr''
<td>top <td>right <td>bottom <td>left
<tr><th>''horizontal-tb'' <th>''rtl''
<td>top <td>left <td>bottom <td>right
<tr><th>''vertical-rl'' <th>''ltr''
<td>right <td>bottom <td>left <td>top
<tr><th>''vertical-rl'' <th>''rtl''
<td>right <td>top <td>left <td>bottom
<tr><th>''vertical-lr'' <th>''rtl''
<td>left <td>bottom <td>right <td>top
<tr><th>''vertical-lr'' <th>''ltr''
<td>left <td>top <td>right <td>bottom
</table>
<p>For example, the “A padding” by default refers to the
'padding-top' and the “B border” is by default the 'border-right'.
</div>
<p>Similarly, the specification sometimes refers to the
<dfn title="inline dimension">inline</dfn> and <dfn title="block flow
dimension">block flow</dfn> dimensions of a box, instead of width and
height, as follows:
<table class=equiv-table>
<tr>
<th>Writing mode
<th>Meaning of “inline dimension”
<th>Meaning of “block flow dimension”
<tr><td><span>horizontal</span> <td>width <td>height
<tr><td><span>vertical</span> <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.
<div class=issue>
<p>[Alternative terminology:]
<p>Similarly, the specification sometimes refers to the <dfn>B-D</dfn>
and <dfn>A-C</dfn> dimensions of a box, instead of width and height,
as follows:
<table class=equiv-table>
<tr>
<th>Writing mode
<th>Meaning of “B-D”
<th>Meaning of “A-C”
<tr><td><span>horizontal</span> <td>width <td>height
<tr><td><span>vertical</span> <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.
</div>
<p>Finally, the <dfn>headside,</dfn> <dfn>endside,</dfn>
<dfn>tailside</dfn> and <dfn>startside</dfn> of a box are defined as
the sides that correspond to the <em>head,</em> <em>end,</em>
<em>tail</em> and <em>start,</em> of the <em>containing block</em> of
the box.
<div class=example>
<p>For example, if a box has a 'writing-mode' of ''horizontal-tb'',
then its top content edge acts as its <em>head</em> content edge,
and the <em>headside</em> edges of its children are therefore their
top edges, independent of what their own 'writing-mode' is.
<div class=figure>
<p><img src="headside" alt="[Figure: the “head content edge” of
the child box the right edge, but the“headside content edge” is
the top.]">
<p class=caption>The second child box is a vertical box and has
its “head” content edge on the right. But its “headside”
content edge is at the top.
</div>
</div>
<div class=issue>
<p>[Alternative terminology:]
<p>Finally, the <dfn>A′,</dfn> <dfn>B′,</dfn>
<dfn>C′</dfn> and <dfn>D′</dfn> sides of a box are defined
as the sides that correspond to the <em>A,</em> <em>B,</em> <em>C</em>
and <em>D</em> sides of the <em>containing block</em> of the box.
<div class=example>
<p>For example, if a box has a 'writing-mode' of ''horizontal-tb'',
then its top content edge acts as its <em>A</em> content edge, and
the <em>A′</em> edges of its children are therefore their top
edges, independent of what their own 'writing-mode' is.
<div class=figure>
<p><img src="headside" alt="[Figure: the “A content edge” of
the child box the right edge, but the “A′ content edge” is
the top.]">
<p class=caption>The second child box is a vertical box and has
its “A” content edge on the right. But its “A′” content edge
is at the top.
</div>
</div><!-- /figure -->
</div><!-- /example -->
</div><!-- /issue -->
<p class=issue>Check terms. At Cambridge ftf Aug 2008 we chose:
Property name: block-flow with values tb | lr | rl | bt. Descriptive
terms: horizontal mode (= tb & bt), vertical mode (= lr &
rl). The May 2012 Writing Modes module now has 'writing-mode' with
values ''horizontal-tb'', ''vertical-rl'' and ''vertical-lr'' (and no
''bt'' anymore).
<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 should
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>Aspect ratios of replaced elements</h2>
<p>For the purposes of the width and height calculations below, CSS
distinguishes four kinds of <em title="replaced element"
class=index>replaced elements</em>:
<dl>
<dt>Type 1: replaced elements with both <em class=index>intrinsic
width</em> and <em class=index>intrinsic height.</em> <dd>These are
replaced elements that are meant to be displayed with a certain fixed
factor (the <em>intrinsic ratio</em>) between their width and height
and also have a default size. Different formats may have different
ways of specifying the size, e.g., a width and a ratio, or a raster
and a resolution in dots per inch. Raster images fall in this
category.
<dt>Type 2: replaced elements with only an <em>intrinsic ratio</em>
<dd>These are replaced elements that are meant to be displayed with a
certain fixed factor between their width and height, but without a
default size. <span class=index>SVG</span> images often fall in the
this category.
<dt>Type 3: replaced elements with a <dfn>complex aspect ratio</dfn>
<dd>These are replaced elements that do not have a <em>fixed</em>
ratio between their width and height, but that do have a functional
relation between them in the sense that for every width there is a
unique height. HTML documents are examples of this: the width can be
chosen freely, but at every width there is a definite intrinsic
height.
<dt>Type 4: replaced elements without an intrinsic ratio <dd>These are
replaced elements that have no relation between their width and
height. Certain <span class=index>SVG</span> images are examples of
this.
</dl>
<p>For <span class=index>raster images</span> without reliable
resolution information, a size of 1 px unit per image source pixel
must be assumed. These images thus are of type 1.
<div class=example>
<p>E.g., in the section on <a href="#inline-replaced">inline replaced
elements,</a> if the replaced element is an HTML document and the
height is specified as ''auto'', e.g.:
<pre>
... <object data="example.html"
style="width: 30em; height: auto"></object>...
</pre>
<p>then the used height will be 150px, which is unlikely to be the
real height of the example.html document. But if the height is
specified as ''complex'', e.g.:
<pre>
... <object data="example.html"
style="width: 30em; height: complex"></object>...
</pre>
<p>then the height will be the height the example.html document
normally has when displayed on its own with the given width. This
enables almost seamless integration of external text in a document,
without a scrollbar or similar. (The external text is still displayed
with its own style sheet.)
</div>
<div class=example>
<p>An (external) mathematical formula in MathML is an example of
replaced content with an intrinsic width and height. Assume the file m.mml
contains a formula, then the HTML fragment
<pre>
... derive <img src="m.mml"
alt="that the sum of p(i) for i greater than 0 equals N">
for the case...
</pre>
<p>renders the formula at its intrinsic size.
</div>
<p class=issue>The mathematical formula would however benefit from a
way to negotiate available space against intrinsic size, or even
negotiate available space against the number of boxes, so that the
formula could be broken in two or more boxes and occupy space on two
or more lines (similar to how lines of text are broken or words are
hyphenated). But an easier solution might be to extend HTML with
native support for math and CSS with math boxes, so that replaced
elements remain single boxes.
<h2>Basic flow layout</h2>
<p>As described in the introduction, elements give rise to boxes and
those boxes are laid out on a <em>canvas.</em> Different kinds of
boxes are laid out differently. This section describes the layout of
one <em>flow</em> of boxes.
<p>The approximate model for the layout of a flow of boxes is that
sibling boxes are laid out one after the other in one long series with
margins between them and parent boxes tightly wrap the series of child
boxes. The 'writing-mode' property of the parent determines if that series
grows down (''tb''), to the left (''rl''), to the right (''lr'') or up
(''bt''). Although the rules below depend on terms that are only
defined further down, the rules are given at the outset, to provide at
least an approximate model of how boxes are positioned relative to one
another.
<p>The following rules define the position of <em>block-level</em>
boxes relative to the box that is their <em>flow root.</em> Other
sections and other modules describe how other boxes are laid out.
E.g., floating boxes are described further down in this module and
absolutely positioned boxes are described in the Absolute Positioning
module [[CSS3POS]].
<p>Before applying these rules, the width, height and margins of each
box must be computed as described in the sections <a
href="#Calculating">“Calculating widths, heights and margins”</a>
and <a href="#Collapsing">“Collapsing margins.”</a>
<ul>
<li>
<p>Consider the first box (in document order) of a set of sibling
boxes that all belong to the same flow. There are four cases:
<ol>
<li>
<p>If none of its margins <span>collapse</span> with its
parent's <span>head</span> margin and the box is
not <span>collapsed through,</span> then the box is placed
such that the box's <span>headside</span> <span>margin
edge</span> touches the
parent's <span>head</span> <span>content edge</span>,
the <span>startside</span> <span>margin edge</span> touches
the parent's <span>start</span> <span>content edge</span> and
the <span>endside</span> <span>margin edge</span> touches the
parent's <span>end</span> <span>content edge.</span>
<p class=issue>[Add illustration.]
<p class=issue>[Alternative terminology:] If none of its
margins <span>collapse</span> with its parent's <span>A</span>
margin and the box is not <span>collapsed through,</span> then
the box is placed such that the box's <span>A′</span>
<span>margin edge</span> touches the parent's <span>A</span>
<span>content edge</span>, the <span>D′</span>
<span>margin edge</span> touches the parent's <span>D</span>
<span>content edge</span> and the <span>B′</span>
<span>margin edge</span> touches the parent's <span>B</span>
<span>content edge.</span>
<li>
<p>If none of its margins <span>collapse</span> with its
parent's <span>head</span> margin but the box
is <span>collapsed through,</span> then its <span>content
edge</span> (which is also its <span>border edge</span>
and <span>padding edge</span>) is defined as what it would
have been if the box had a non-zero <span>tailside</span>
border. (I.e., recompute the margins given that border and
then apply the previous rule.)
<p class=note>Note that the box is effectively invisible, but
the edges have to be defined to position any descendants, such
as floating or absolutely positioned children.
<li>
<p>If exactly one of its margins collapses with its
parent's <span>head</span> margin, then the box is placed such
that the box's <span>headside</span> <span>border edge</span>
touches the parent's <span>head</span> <span>content
edge,</span> the <span>startside</span> <span>margin
edge</span> touches the
parent's <span>start</span> <span>content edge</span> and
the <span>endside</span> <span>margin edge</span> touches the
parent's <span>end</span> <span>content edge.</span>
<p class=issue>[Add illustration.]
<li>
<p>If two of its margins collapse with its
parent's <span>head</span> margin, then its position is such
that its <span>content edge</span> (which is also
its <span>border edge</span>) touches its
parent's <span>head</span> <span>border edge</span> and that
its <span>startside</span> <span>margin edge</span> touches
its parent's <span>start</span> <span>content edge</span> and
its <span>endside</span> <span>margin edge</span> touches the
parent's <span>end</span> <span>content edge.</span>
<p class=note>Note that the box is effectively invisible, but
the edges have to be defined to position any descendants.
</ol>
<li>
<p>For a box that has a preceding sibling in the same flow there
are two cases:
<ol>
<li>
<p>If the box is not <span>collapsed through,</span> it is
positioned such that its <span>margin edge</span> touches the
parent's <span>start</span> <span>content edge</span>
and <span>end</span> <span>content edge</span> and such that
its content edge on the touches
the <span class=issue>[...]</span>
<li>
<p>A box that has a preceding sibling in the same flow and that
is <span>collapsed
through,</span> <span class=issue>[...]</span>
</ol>
</ul>
<h2>Types of boxes</h2>
<p>The layout of boxes in the flow is in lar
2334
ge part determined by the
interplay of the 'display' properties of an element and its parent,
and then fine-tuned with margins and padding.
<h3 id=display>The display property</h3>
<table class="propdef">
<tr><td>Name: <td><dfn>display</dfn>
<tr><td>Value: <td>inline | block | inline-block | list-item |
run-in | compact | table | inline-table | table-row-group |
table-header-group | table-footer-group | table-row |
table-column-group | table-column | table-cell | table-caption |
ruby | ruby-base | ruby-text | ruby-base-group | ruby-text-group |
align-box | none
<tr><td>Initial: <td>inline
<tr><td>Applies to:<td>all elements
<tr><td>Inherited: <td>no
<tr><td>Percentages: <td>N/A
<tr><td>Media: <td>visual (''none'' applies to all media)
<tr><td>Computed value: <td>specified value, except for floats, root
elements and positioned elements; see text
</table>
<p class=issue>There is an old proposal to split 'display' into
display-role (the function of the element in its parent) and
display-model (how the element lays out it children). That allows some
combinations that have no keyword, such as a table cell
('display-role: table-cell') that is itself a table ('display-model:
table'), without the need for an extra wrapper element. It allows
certain things (for math layout, e.g.), but is not easy to use. An
alternative proposal is an '::outside' pseudo-element to create an
extra box on which to set a different 'display' value. That is not
easy either, and doesn't cascade well. And a third proposal is to
allow two values on 'display': if there are two (in any order), one is
the role and the other the model, unless the pair makes no sense. That
doesn't make the concept any easier, but it hides the complexity
better.
<p>This property, in combination with 'float' and 'position',
determines the type of box or boxes that are generated for an element.
The values are as follows:
<dl>
<dt>inline <dd>Inline boxes.
<dt>block <dd>Block boxes.
<dt>inline-block <dd>A block box, which itself is flowed as a single
inline box, similar to a replaced element. The inside of an
inline-block is formatted as a block box, and the box itself is
formatted as an inline box.
<dt>list-item <dd>One or more block boxes and one marker box. Marker
boxes are defined in the Lists module [[CSS3LIST]]. <span
class=issue>If the Lists module is not ready, define the position of
the marker and the list-style property here? Or refer to CSS 2.1
instead?</span>
<dt>run-in <dd>Either block or inline boxes, depending on context
(see <a href="#run-in-boxes">Run-in boxes</a>). Properties apply to
run-in boxes based on their final status (<span>inline-level</span>
or <span>block-level</span>).
<dt>compact <dd>Either block boxes or a marker box, depending on
context (see <a href="#compact-boxes">Compact boxes</a>). Properties
apply to compact boxes based on their final status.
<dt>table, inline-table, table-row-group, table-header-group,
table-footer-group, table-row, table-column-group, table-column,
table-cell, table-caption <dd>See the Tables module [[CSS3TBL]].
<dt>ruby, ruby-base, ruby-text, ruby-base-group, ruby-text-group
<dd>See the Ruby module [[CSS3RUBY]].
<dt>align-box <span class=issue>or container?</span> <dd>Like
''block'', but forces the element to be a <em>flow root,</em>,
which, e.g., stops its margins from collapsing with margins of child
elements and includes floating children in its
height. <span class=issue>[C.f.
the <a href="#contain-floats">discussion of how to force an element
to contain floats.</a>]</span>
<dt>none <dd>This value causes an element to not appear in the
formatting structure (i.e., in visual media, the element generates
no boxes and has no effect on layout). Descendant elements do not
generate any boxes either; the element and its content are removed
from the formatting structure entirely. This behavior
<strong>cannot</strong> be overridden by setting the 'display'
property on the descendants.
</dl>
<p class=note>Note that ''none'' does not create an invisible box; it
creates no box at all. See 'visibility' for a mechanisms that enables
an element to generate boxes that affect formatting but are not
visible themselves.
<p class=note>Note that both 'clear-after' and ''align-box'' can be
used to force the next element after this one to start after any
floats inside this element, but the effect is not exactly the same.
E.g., 'display: box' also affects certain forms of margin
collapsing.
<p class=note>Note that 'vertical-al ign' applies to ''align-box''
elements, hence the name. The 'vertical-align' property doesn't apply
to other block-level elements, except ''table-cell'' elements.
<p class=issue>Any sense in vertically spreading out the contents,
something like 'vertical-align: justify'?
<p class=issue>Simpler to not use 'vertical-align', but creating
''top-box'', ''middle-box'' and ''bottom-box''?
<div class=example>
<p>The 'vertical-align' property applies to ''align-box''
elements <span class=issue>[check in [[!CSS3TEXT]]!]</span>, and can
thus be used to create vertically centered content, without wrapping
the content in a table (which may not be always possible, and also
causes the 'width' property to behave differently).
<pre>
div.slide {
display: align-box;
height: 15em;
vertical-align: middle;
border: thin solid }
</pre>
<p>with a document fragment like this:
<pre>
<div class=slide>
<ul>
<li>Bullet lists are boring
<li>They distract from the speaker
<li>Don't use them!
</ul>
</div>
</pre>
<p>might look like this figure:
<div class=figure>
<p><img src="align-box.png" alt="A 15 em high box with three bullet
items in the center">
<p class=caption>The 'vertical-align: middle' causes the content of
the ''align-box'' to be vertically centered.
</div>
</div>
<p>The computed value of 'display' depends on 'position' [[CSS3POS]],
'float' and 'overflow':
<ol>
<li>If the specified value of 'display' is ''none'', then the
computed value is ''none'' (and 'overflow', 'float' and 'position'
do not apply).
<li>Otherwise, if 'position' is ''absolute'' or ''fixed'', or if
'float' is not ''none'', or if 'overflow' is not ''visible'', or if
the element is the root element, then the computed value of
'display' is set according to the following table:
<table class=equiv-table>
<thead>
<tr><th>Specified value <th>Computed value
<tbody>
<tr><td>inline-table <td>table
<tr><td>inline, run-in, table-row-group,
table-column, table-column-group,
table-header-group, table-footer-group,
table-row, table-cell, table-caption,
inline-block <td>block
<tr><td>others <td>same as specified
</table>
<li>Otherwise, the computed value of 'display' is the same as the
specified value.
</ol>
<h3>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). If an element that is rendered according to the CSS
box model has a child that is to be rendered with a different model,
that child needs to have a 'display' property with a value that
indicates that the child is not in the box model.
<p>Such a child is treated as a <em>replaced element</em> for the
purposes of determining its size, position, margins, padding and
border.
<p class=issue>Should we allow a more complex model, where such a
child may negotiate with the CSS environment to have several boxes and
several baselines, so that it can take part in line breaking and page
breaking?
<p>This specification defines no value(s) for the 'display' property
that indicate that an element is formatted according to a different
model than the box model, but separate specifications may do so.
<h3>Block-level boxes, containing blocks, flows and anonymous
boxes</h3>
<p>A <dfn>block-level</dfn> box is a box that has a <span>computed
value</span> for 'display' of ''block'', ''align-box'', ''list-item'',
''table'', ''table-*'' (i.e., all table boxes, see [[CSS3TBL]]),
''run-in'' (under
certain circumstances, see <a href="#run-in-boxes">“Run-in boxes”
</a>), or ''compact'' (under certain circumstances, see <a
href="#compact-boxes">“Compact boxes”</a>).
<p>An <dfn>inline-level</dfn> box is a box that has a <span>computed
value</span> 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).
Other modules (e.g., [[CSS3TBL]], [[!CSS3TEXT]]) may also define anonymous
boxes. The anonymous boxes defined by this module are the following:
<ul>
<!--
<li>An ''inline-table'' element creates one box with ''inline-table'' as
the value for 'display', which contains one anonymous box with ''table''
as the value.
<li>An ''inline-block'' element creates one box with ''inline-block'' as
the value for 'display', containing one anonymous box with ''block'' as
the value.
<li>A <span>block-level</span> element that has a
'writing-mode' of ''lr'' or
''rl'' and a parent with a 'writing-mode' of ''tb'' (or vice-versa)
generates one or more block-level boxes with the same 'writing-mode'
as the parent, each of which has one anonymous child box with a 'display'
of ''block'' and the 'writing-mode' of the element itself. <span
class=issue>[Coordinate this with CSS3-WRITING-MODES]</span>
-->
<li>A <span>block-level box</span> may contain either <span
title="line box">line boxes</span> or <span>block-level</span>
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''.
</ul>
<div class=example>
<p>An example of the last point above 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: