-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathOverview.html
More file actions
8112 lines (6232 loc) · 304 KB
/
Overview.html
File metadata and controls
8112 lines (6232 loc) · 304 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
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">
<html>
<head
profile="http://www.w3.org/2006/03/hcard http://microformats.org/wiki/rel-license">
<title>CSS basic box model</title>
<style type="text/css">
ol.stack p {margin-top: 0}
</style>
<link href="../default.css" rel=stylesheet title=Default type="text/css">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
title=Default type="text/css">
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1>CSS basic box model</h1>
<h2 class="no-num no-toc" id=longstatus-date-26-sep-2006>Editor's Draft 16
November 2011</h2>
<dl>
<dt>This version:
<dd><a href="http://www.w3.org/TR/2011/ED-css3-box-20111116/">
http://www.w3.org/TR/2011/ED-css3-box-20111116</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>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2011 <a
href="http://www.w3.org/"><acronym
title="World Wide Web Consortium">W3C</acronym></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><acronym
title="Massachusetts Institute of Technology">MIT</acronym></a>, <a
href="http://www.ercim.eu/"><acronym
title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>,
<a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id=abstract>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
1DDA
can be mixed.
<h2 class="no-toc no-num" id=status-of-this-document>Status of this
document</h2>
<!--begin-status-->
<p>This is a public copy of the editors' draft. It is provided for
discussion only and may change at any moment. Its publication here does
not imply endorsement of its contents by W3C. Don't cite this document
other than as work in progress.
<p>The (<a
href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public
mailing list <a
href="mailto:www-style@w3.org?Subject=%5Bcss3-box%5D%20PUT%20SUBJECT%20HERE">
www-style@w3.org</a> (see <a
href="http://www.w3.org/Mail/Request">instructions</a>) is preferred for
discussion of this specification. When sending e-mail, please put the text
“css3-box” in the subject, preferably like this:
“[<!---->css3-box<!---->] <em>…summary of
comment…</em>”
<p>This document was produced by the <a href="/Style/CSS/members">CSS
Working Group</a> (part of the <a href="/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent
Policy</a>. W3C maintains a <a href="/2004/01/pp-impl/32061/status"
rel=disclosure>public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a
href="/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the
W3C Patent Policy</a>.</p>
<!--end-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 <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>. 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" id=table-of-contents>Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#how-to-read-this-specification"><span class=secno>1.
</span>How to read this specification</a>
<li><a href="#dependencies-on-other-modules"><span class=secno>2.
</span>Dependencies on other modules</a>
<li><a href="#introduction-amp-definitions"><span class=secno>3.
</span>Introduction & definitions</a>
<li><a href="#the-viewport-and-the-canvas"><span class=secno>4. </span>The
viewport and the canvas</a>
<li><a href="#aspect-ratios-of-replaced-elements"><span class=secno>5.
</span>Aspect ratios of replaced elements</a>
<li><a href="#basic-flow-layout"><span class=secno>6. </span>Basic flow
layout</a>
<li><a href="#types-of-boxes"><span class=secno>7. </span>Types of
boxes</a>
<ul class=toc>
<li><a href="#display"><span class=secno>7.1. </span>The display
property</a>
<li><a href="#mixing-the-box-model-with-other-formatti"><span
class=secno>7.2. </span>Mixing the box model with other formatting
models</a>
<li><a href="#block-level-boxes-containing-blocks-flow"><span
class=secno>7.3. </span>Block-level boxes, containing blocks, flows and
anonymous boxes</a>
<li><a href="#run-in-boxes"><span class=secno>7.4. </span>Run-in
boxes</a>
<li><a href="#compact-boxes"><span class=secno>7.5. </span>Compact
boxes</a>
</ul>
<li><a href="#the-padding-properties"><span class=secno>8. </span>The
padding properties</a>
<li><a href="#margins"><span class=secno>9. </span>Margins</a>
<ul class=toc>
<li><a href="#the-margin-properties"><span class=secno>9.1. </span>The
margin properties</a>
<li><a href="#collapsing-margins"><span class=secno>9.2.
</span>Collapsing margins</a>
</ul>
<li><a href="#the-width-and-height-properties"><span class=secno>10.
</span>The width and height properties</a>
<li><a href="#min-max"><span class=secno>11. </span>The min-width,
max-width, min-height and max-height properties</a>
<li><a href="#intrinsic"><span class=secno>12. </span>Definition of
intrinsic sizes – high quality</a>
<li><a href="#intrinsic-low"><span class=secno>13. </span>Definition of
intrinsic sizes – low quality</a>
<li><a href="#Calculating"><span class=secno>14. </span>Calculating
widths, heights and margins</a>
<ul class=toc>
<li><a href="#inline-non-replaced"><span class=secno>14.1.
</span>Inline, non-replaced elements</a>
<li><a href="#inline-replaced"><span class=secno>14.2. </span>Inline or
floating, replaced elements</a>
<li><a href="#blockwidth"><span class=secno>14.3. </span>Block-level,
non-replaced elements in normal flow when ‘<code
class=property>overflow</code>’ computes to ‘<code
class=css>visible</code>’</a>
<li><a href="#other-block-level-non-replaced-elements-"><span
class=secno>14.4. </span>Other block-level, non-replaced elements in
normal flow</a>
<li><a href="#inline-block-or-floating-non-replaced-el"><span
class=secno>14.5. </span>‘<code
class=property>Inline-block</code>’ or floating, non-replaced
elements</a>
<li><a href="#abs-non-replaced-width"><span class=secno>14.6.
</span>Absolutely positioned, non-replaced elements</a>
<li><a href="#abs-replaced"><span class=secno>14.7. </span>Absolutely
positioned, replaced elements</a>
<li><a href="#block-level-replaced-elements-in-normal-"><span
class=secno>14.8. </span>Block-level, replaced elements in normal
flow</a>
<li><a href="#floating-non-replaced-elements"><span class=secno>14.9.
</span>Floating, non-replaced elements</a>
<li><a href="#root-height"><span class=secno>14.10. </span>Auto heights
for flow roots</a>
</ul>
<li><a href="#the-float-property"><span class=secno>15. </span>The float
property</a>
<ul class=toc>
<li><a href="#introduction-to-floats"><span class=secno>15.1.
</span>Introduction to floats</a>
<li><a href="#rules-for-positioning-floats"><span class=secno>15.2.
</span>Rules for positioning floats</a>
</ul>
<li><a href="#the-clear-property"><span class=secno>16. </span>The clear
property</a>
<li><a href="#the-clear-after-property"><span class=secno>17. </span>The
clear-after property</a>
<li><a href="#overflow0"><span class=secno>18. </span>Overflow</a>
<ul class=toc>
<li><a href="#overflow"><span class=secno>18.1. </span>The overflow,
overflow-x and overflow-y properties</a>
</ul>
<li><a href="#the-visibility-property"><span class=secno>19. </span>The
visibility property</a>
<li><a href="#the-alignment-property"><span class=secno>20. </span>The
alignment property</a>
<li><a href="#the-child-align-property"><span class=secno>21. </span>The
child-align property</a>
<li><a href="#stacking-contexts"><span class=secno>22. </span>Stacking
contexts</a>
<ul class=toc>
<li><a href="#definitions"><span class=secno>22.1.
</span>Definitions</a>
<li><a href="#painting-order"><span class=secno>22.2. </span>Painting
order</a>
<li><a href="#notes"><span class=secno>22.3. </span>Notes</a>
<li><a href="#the-ltnumbergt-value"><span class=secno>22.4. </span>The
<number> value</a>
<li><a href="#auto"><span class=secno>22.5. </span>The auto value</a>
<li><a href="#complex-size"><span class=secno>22.6. </span>Algorithm for
shrink-wrapping replaced elements with complex width/height</a>
</ul>
<li><a href="#the-float-displace-property"><span class=secno>23.
</span>The ‘<code class=property>float-displace</code>’
property</a>
<li><a href="#the-indent-edge-reset-property"><span class=secno>24.
</span>The ‘<code class=property>indent-edge-reset</code>’
property</a>
<li><a href="#conformance-and-profiles"><span class=secno>25.
</span>Conformance and profiles</a>
<li><a href="#exit"><span class=secno>26. </span>CR exit criteria</a>
<li><a href="#acknowledgments"><span class=secno>27.
</span>Acknowledgments</a>
<li class=no-num><a href="#references">References</a>
<li class=no-num><a href="#index">Index</a>
<li class=no-num><a href="#property-index">Property index</a>
</ul>
<!--end-toc-->
<h2 id=how-to-read-this-specification><span class=secno>1. </span>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 <a
href="#CSS3CASCADE"
rel=biblioentry>[CSS3CASCADE]<!--{{CSS3CASCADE}}--></a> and
“Media” by the Media Queries specification <a href="#MEDIAQ"
rel=biblioentry>[MEDIAQ]<!--{{MEDIAQ}}--></a>.
<p>The specification may refer to the <a href="#used-value."><em>used
value</em></a> and the <a href="#computed-value"><em>computed
value</em></a> of a property. Unless stated explicitly, the short form
“value” means the computed value.
<h2 id=dependencies-on-other-modules><span class=secno>2.
</span>Dependencies on other modules</h2>
<p>This CSS module depends on the following other CSS modules:
<ul>
<li><cite>CSS Writing Modes Module</cite> <a href="#CSS3-WRITING-MODES"
rel=biblioentry>[CSS3-WRITING-MODES]<!--{{!CSS3-WRITING-MODES}}--></a>
– switch between vertical and horizontal text, properties <dfn
id=block-flow>block-flow</dfn> and <dfn id=direction>direction</dfn>,
definitions of the terms <dfn id=block-flow-direction>block flow
direction</dfn> and <dfn id=inline-base-direction.>inline base
direction.</dfn>
<li><cite>CSS Syntax Module</cite> <a href="#CSS3SYN"
rel=biblioentry>[CSS3SYN]<!
62B4
--{{!CSS3SYN}}--></a> – syntax of
properties and values
<li><cite>CSS Values and Units Module</cite> <a href="#CSS3VAL"
rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a> – definitions of
value types <dfn id=ltnumbergt><var><number></var></dfn>, <dfn
id=ltanglegt><var><angle></var></dfn> and <dfn
id=ltlengthgt><var><length></var></dfn>; defines the terms <dfn
id=computed-value>computed value</dfn> and <dfn id=used-value.>used
value.</dfn>
<li><cite>CSS Text Module</cite> <a href="#CSS3TEXT"
rel=biblioentry>[CSS3TEXT]<!--{{!CSS3TEXT}}--></a> – inline layout
and definition of <dfn id=line-box.>line box.</dfn>
<li><cite>CSS Generated and Replaced Content module</cite> <a
href="#CSS3GENCON" rel=biblioentry>[CSS3GENCON]<!--{{!CSS3GENCON}}--></a>
– defines the terms <dfn id=replaced-element>replaced element</dfn>
and <dfn id=intrinsic0>intrinsic</dfn> size (and intrinsic ratio).
<li><cite>CSS Backgrounds and Borders Module</cite> <a href="#CSS3BG"
rel=biblioentry>[CSS3BG]<!--{{!CSS3BG}}--></a> – defines <dfn
id=ltbg-positiongt><var><bg-position></var></dfn>
<li><cite>CSS Basic User Interface Module</cite> <a href="#CSS3UI"
rel=biblioentry>[CSS3UI]<!--{{!CSS3UI}}--></a> – defines <dfn
id=box-sizing>box-sizing</dfn>
<li><cite>CSS 2D Transforms</cite> <a href="#CSS3-2D-TRANSFORMS"
rel=biblioentry>[CSS3-2D-TRANSFORMS]<!--{{!CSS3-2D-TRANSFORMS}}--></a>
– defines <dfn id=transform>transform</dfn>
</ul>
<h2 id=introduction-amp-definitions><span class=secno>3.
</span>Introduction & definitions</h2>
<p class=issue>Investigate if it is possible to make a pseudo-element to
select anonymous boxes (‘<code class=css>::paragraph</code>’).
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 <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>, 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 id=tree
title="tree!!of elements|document tree|element tree">tree</span> of <dfn
id=elements. 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 id=root-element.>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 <a
href="#canvas"><em>canvas</em></a> depend on their properties. We say that
an element <dfn id=generates title="generated box">generates</dfn> one or
more boxes. There are <a href="#block-level"><em>block-level</em></a>
boxes, <a href="#line-box."><em title="line box">line boxes</em></a> and
<a href="#inline-level"><em title=inline-level>inline-level
boxes.</em></a> 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
id=contains>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 alt="Schematic representation of rel" src=box-intro.png>
<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 <a
href="#generates" title="generated box">generated</a> directly by the
element, or it is an <a href="#anonymous-box"><em>anonymous box</em></a>
(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
id=wysiwyg-document-editors>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
alt="Diagram of a typical box, showing the content, padding, border and margin areas"
src=box.png>
<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 <a
href="#collapse."><em title=collapse>collapsing.</em></a>
<p>Each box has a <dfn id=content-area>content area</dfn> (a.k.a. <dfn
id=content-box>content box</dfn>). The rectangle that bounds this area is
the <dfn id=content-edge.>content edge.</dfn> Around the content area is
the <dfn id=padding-area>padding area</dfn> and its outside bounds are
called the <dfn id=padding-edge.>padding edge.</dfn> The padding area and
content area together form the <dfn id=padding-box.>padding box.</dfn>
Outside the padding is the <dfn id=border-area>border area</dfn> and the
outside boundary of that area is the <dfn id=border-edge.>border
edge.</dfn> The border area, padding area and content area together form
the <dfn id=border-box.>border box.</dfn> Finally, outside the border is
the <dfn id=margin-area>margin area</dfn> and its outer edge is the <dfn
id=margin-edge.>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><a href="#line-box."><em title="line box">Line boxes</em></a> 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 ‘<code class=property>border-radius</code>’ <a
href="#CSS3BG" rel=biblioentry>[CSS3BG]<!--{{CSS3BG}}--></a>.
<p>A box or element is <dfn id=vertical>vertical</dfn> if its ‘<a
href="#block-flow"><code class=property>block-flow</code></a>’
property is ‘<code class=css>lr</code>’ or ‘<code
class=css>rl</code>’, otherwise it is <dfn
id=horizontal.>horizontal.</dfn> The <dfn id=writing-mode>writing
mode</dfn> of a box or element is the pair of values of its ‘<a
href="#block-flow"><code class=property>block-flow</code></a>’ and
‘<a href="#direction"><code
class=property>direction</code></a>’ (‘<code
class=css>ltr</code>’ or ‘<code class=css>rtl</code>’).
I.e., there are eight writing modes: four horizontal ones and four
vertical ones.
<p>This specification sometimes refers to abstract edges <dfn
id=head>head,</dfn> <dfn id=end>end,</dfn> <dfn id=tail>tail</dfn> and
<dfn id=start>start,</dfn> which are relative to the writing mode of a
box. They map to top, right, bottom and left as follows:
<table class=equiv-table>
<thead>
<tr>
<th>Value of ‘<a href="#block-flow"><code
class=property>block-flow</code></a>’
<th>Value of ‘<a href="#direction"><code
class=property>direction</code></a>’
<th>Meaning of “head”
<th>Meaning of “end”
<th>Meaning of “tail”
<th>Meaning of “start”
<tbody>
<tr>
<th>‘<code class=css>tb</code>’
<th>‘<code class=css>ltr</code>’
<td>top
<td>right
<td>bottom
<td>left
<tr>
<th>‘<code class=css>tb</code>’
<th>‘<code class=css>rtl</code>’
<td>top
<td>left
<td>bottom
<td>right
<tr>
<th>‘<code class=css>bt</code>’
<th>‘<code class=css>ltr</code>’
<td>bottom
<td>right
<td>top
<td>left
<tr>
<th>‘<code class=css>bt</code>’
<th>‘<code class=css>rtl</code>’
<td>bottom
<td>left
<td>top
<td>right
<tr>
<th>‘<code class=css>rl</code>’
<th>‘<code class=css>ltr</code>’
<td>right
<td>bottom
<td>left
<td>top
<tr>
<th>‘<code class=css>rl</code>’
<th>‘<code class=css>rtl</code>’
<td>right
<td>top
<td>left
<td>bottom
<tr>
<th>‘<code class=css>lr</code>’
<th>‘<code class=css>rtl</code>’
<td>left
<td>bottom
<td>right
<td>top
<tr>
<th>‘<code class=css>lr</code>’
<th>‘<code class=css>ltr</code>’
<td>left
<td>top
<td>right
<td>bottom
</table>
<p>For example, the “head padding” by default refers to the ‘<a
href="#padding-top"><code class=property>padding-top</code></a>’ and
the “end border” is by default the ‘<code
class=property>border-right</code>’.
<p>Similarly, the specification sometimes refers to the <dfn id=inline
title="inline dimension">inline</dfn> and <dfn id=block-flow0
title="block flow dimension">block flow</dfn> dimensions of a box, instead
of width and height, as follows:
<table class=equiv-table>
<tbody>
<tr>
<th>Value of ‘<a href="#block-flow"><code
class=property>block-flow</code></a>’
<th>Meaning of “inline dimension”
<th>Meaning of “block flow dimension”
<tr>
<td>tb
<td>width
<td>height
<tr>
<td>rl
<td>height
<td>width
<tr>
<td>lr
<td>height
<td>width
</table>
<p>These correspond to the dimensions in the <a
href="#inline-base-direction."><em>inline base direction</em></a> and the
<a href="#block-flow-direction"><em>block flow direction,</em></a>
respectively.
<p>Finally, the <dfn id=headside>headside,</dfn> <dfn
id=endside>endside,</dfn> <dfn id=tailside>tailside</dfn> and <dfn
id=startside>startside</dfn> of a box are defined as the sides that
correspond to the <a href="#head"><em>head,</em></a> <a
href="#end"><em>end,</em></a> <a href="#tail"><em>tail</em></a> and <a
href="#start"><em>start,</em></a> of the <a
href="#containing-block"><em>containing block</em></a> of the box.
<div class=example>
<p>For example, if a box has a ‘<a href="#block-flow"><code
class=property>block-flow</code></a>’ of ‘<code
class=css>tb</code>’, then its top content edge acts as its <a
href="#head"><em>head</em></a> content edge, and the <a
href="#headside"><em>headside</em></a> edges of its children are
therefore their top edges, independent of what their own ‘<a
href="#block-flow"><code class=property>block-flow</code></a>’ is.
<div class=figure>
<p><img
alt="[Figure: the “head content edge” of the child box the right edge, but the“headside content edge” is the top.]"
src=headside>
<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>
<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)
<h2 id=the-viewport-and-the-canvas><span class=secno>4. </span>The viewport
and the canvas</h2>
<p>User agents for continuous media generally offer users a <dfn
id=viewport>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
href="#initial-containing-block."><em>initial containing block</em></a>).
<p>When the viewport is smaller than the area of the <a
href="#canvas"><em>canvas</em></a> (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 id=canvas>canvas</dfn> describes the space
where the formatting structure is rendered. The canvas is infinite for
each dimension of the space.
<h2 id=aspect-ratios-of-replaced-elements><span class=secno>5.
</span>Aspect ratios of replaced elements</h2>
<p>For the purposes of the width and height calculations below, CSS
distinguishes four kinds of <a href="#replaced-element"><em class=index
id=replaced-elements title="replaced element">replaced elements</em></a>:
<dl>
<dt>Type 1: replaced elements with both <em class=index
id=intrinsic-width>intrinsic width</em> and <em class=index
id=intrinsic-height.>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 id=svg>SVG</span> images often fall in
the this category.
<dt>Type 3: replaced elements with a <dfn id=complex-aspect-ratio>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 id=svg0>SVG</span> images are
examples of this.
</dl>
<p>For <span class=index id=raster-images>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 ‘<code class=css>auto</code>’, 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
‘<code class=css>complex</code>’, 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 id=basic-flow-layout><span class=secno>6. </span>Basic flow layout</h2>
<p>As described in the introduction, elements give rise to boxes and those
boxes are laid out on a <a href="#canvas"><em>canvas.</em></a> Different
kinds of boxes are laid out differently. This section describes the layout
of one <a href="#flow"><em>flow</em></a> 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
‘<a href="#block-flow"><code
class=property>block-flow</code></a>’ property of the parent
determines if that series grows down (‘<code
class=css>tb</code>’), to the left (‘<code
class=css>rl</code>’), to the right (‘<code
class=css>lr</code>’) or up (‘<code
class=css>bt</code>’). 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 <a
href="#block-level"><em>block-level</em></a> boxes relative to the box
that is their <a href="#flow-root"><em>flow root.</em></a> 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 <a href="#CSS3POS"
rel=biblioentry>[CSS3POS]<!--{{CSS3POS}}--></a>.
<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 <a href="#collapse.">collapse</a> with its
parent's <a href="#head">head</a> margin and the box is not <a
href="#collapsed-through">collapsed through,</a> then the box is
placed such that the box's <a href="#headside">headside</a> <a
href="#margin-edge.">margin edge</a> touches the parent's <a
href="#head">head</a> <a href="#content-edge.">content edge</a>, the
<a href="#startside">startside</a> <a href="#margin-edge.">margin
edge</a> touches the parent's <a href="#start">start</a> <a
href="#content-edge.">content edge</a> and the <a
href="#endside">endside</a> <a href="#margin-edge.">margin edge</a>
touches the parent's <a href="#end">end</a> <a
href="#content-edge.">content edge.</a>
<p class=issue>[Add illustration.]
<li>
<p>If none of its margins <a href="#collapse.">collapse</a> with its
parent's <a href="#head">head</a> margin but the box is <a
href="#collapsed-through">collapsed through,</a> then its <a
href="#content-edge.">content edge</a> (which is also its <a
href="#border-edge.">border edge</a> and <a
href="#padding-edge.">padding edge</a>) is defined as what it would
have been if the box had a non-zero <a href="#tailside">tailside</a>
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 <a
href="#head">head</a> margin, then the box is placed such that the
box's <a href="#headside">headside</a> <a href="#border-edge.">border
edge</a> touches the parent's <a href="#head">head</a> <a
href="#content-edge.">content edge,</a> the <a
href="#startside">startside</a> <a href="#margin-edge.">margin
edge</a> touches the parent's <a href="#start">start</a> <a
href="#content-edge.">content edge</a> and the <a
href="#endside">endside</a> <a href="#margin-edge.">margin edge</a>
touches the parent's <a href="#end">end</a> <a
href="#content-edge.">content edge.</a>
<p class=issue>[Add illustration.]
<li>
<p>If two of its margins collapse with its parent's <a
href="#head">head</a> margin, then its position is such that its <a
href="#content-edge.">content edge</a> (which is also its <a
href="#border-edge.">border edge</a>) touches its parent's <a
href="#head">head</a> <a href="#border-edge.">border edge</a> and that
its <a href="#startside">startside</a> <a href="#margin-edge.">margin
edge</a> touches its parent's <a href="#start">start</a> <a
href="#content-edge.">content edge</a> and its <a
href="#endside">endside</a> <a href="#margin-edge.">margin edge</a>
touches the parent's <a href="#end">end</a> <a
href="#content-edge.">content edge.</a>
<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 <a href="#collapsed-through">collapsed
through,</a> it is positioned such that its <a
href="#margin-edge.">margin edge</a> touches the parent's <a
href="#start">start</a> <a href="#content-edge.">content edge</a> and
<a href="#end">end</a> <a href="#content-edge.">content edge</a> 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 <a
href="#collapsed-through">collapsed through,</a> <span
class=issue>[...]</span>
</ol>
</ul>
<h2 id=types-of-boxes><span class=secno>7. </span>Types of boxes</h2>