-
Notifications
You must be signed in to change notification settings - Fork 707
/
Copy pathOverview.html
8575 lines (6495 loc) · 308 KB
/
Overview.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" "">
<html>
<head
profile="http://dublincore.org/documents/2008/08/04/dc-html/ 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="http://purl.org/dc/terms/" rel=schema.dcterms>
<link href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=dcterms.rights>
<meta content="CSS basic box model" name=dcterms.title>
<meta content=text name=dcterms.type>
<meta content=2014-09-30 name=dcterms.date>
<meta content="Bert Bos" name=dcterms.creator>
<meta content="Anton Prowse" name=dcterms.creator>
<meta content=W3C name=dcterms.publisher>
<meta content="http://dev.w3.org/csswg/css-box-3/" name=dcterms.identifier>
<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: 1;
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: 2}
#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-ED.css" rel=stylesheet
title=Default type="text/css">
<link href="#contents" rel=contents>
<link href="#index" rel=index><!--
<pre class=metadata>
Title: CSS basic box model
Shortname: css-box
Level: 3
Status: ED
ED: http://dev.w3.org/csswg/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>
-->
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="https://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1>CSS basic box model</h1>
<h2 class="no-num no-toc">Editor's Draft 30 September 2014</h2>
<dl>
<dt>This version:
<dd><a
href="http://dev.w3.org/csswg/css-box-3/">http://dev.w3.org/csswg/css-box-3/</a>
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css-box-3">http://www.w3.org/TR/css-box-3/</a>
<dt>Previous version:
<dd><a
href="http://www.w3.org/TR/2007/WD-css3-box-20070809/">http://www.w3.org/TR/2007/WD-css3-box-20070809/</a>
<dt>Feedback:
<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
href="http://lists.w3.org/Archives/Public/www-style/"
rel=discussion>archives</a>)
<dt>Editors:
<dd class="h-card vcard"><a class="p-name fn u-url url"
href="http://www.w3.org/People/Bos/" rel=author>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>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2014 <a href="http://www.w3.org/"><abbr
title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><abbr
title="Massachusetts Institute of Technology">MIT</abbr></a>, <a
href="http://www.ercim.eu/"><abbr
title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>,
<a href="http://www.keio.ac.jp/">Keio</a>, <a
href="http://ev.buaa.edu.cn/">Beihang</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">Abstract</h2>
<h2 class="no-toc no-num">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=%5Bcss-box-3%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
“css-box-3” in the subject, preferably like this:
“[<!---->css-box-3<!---->] <em>…summary of comment…</em>”
<p>This document was produced by the <a
href="http://www.w3.org/Style/CSS/members">CSS Working Group</a> (part of
the <a href="http://www.w3.org/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
2004 W3C Patent Policy</a>. W3C maintains a <a
href="http://www.w3.org/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="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="http://www.w3.org/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.
<div> <input id=annoying-warning title="hide warning" type=checkbox> <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 <a href="#ref-CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> 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 <a href="#ref-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">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="#flows"><span class=secno>5. </span>Flows</a>
<li><a href="#types-of-boxes"><span class=secno>6. </span>Types of
boxes</a>
<ul class=toc>
<li><a href="#block-level-boxes-containing-blocks-flow"><span
class=secno>6.1. </span>Block-level boxes, containing blocks, flows and
anonymous boxes</a>
<li><a href="#mixing-the-box-model-with-other-formatti"><span
class=secno>6.2. </span>Mixing the box model with other formatting
models</a>
</ul>
<li><a href="#the-padding-properties"><span class=secno>7. </span>The
padding properties</a>
<li><a href="#the-margin-properties"><span class=secno>8. </span>The
margin properties</a>
<li><a href="#the-width-and-height-properties"><span class=secno>9.
</span>The width and height properties</a>
<li><a href="#min-max"><span class=secno>10. </span>The min-width,
max-width, min-height and max-height properties</a>
<li><a href="#intrinsic"><span class=secno>11. </span>Definition of
min-content/max-content</a>
<li><a href="#aspect-ratios-of-replaced-elements"><span class=secno>12.
</span>Aspect ratios of replaced elements</a>
<li><a href="#block-level-formatting"><span class=secno>13.
</span>Block-level formatting</a>
<ul class=toc>
<li><a href="#collapsing-margins"><span class=secno>13.1.
</span>Collapsing margins</a>
</ul>
<li><a href="#inline-level-formatting"><span class=secno>14.
</span>Inline-level formatting</a>
<li><a href="#Calculating"><span class=secno>15. </span>Calculating
widths, heights and margins</a>
<ul class=toc>
<li><a href="#inline-non-replaced"><span class=secno>15.1.
</span>Inline, non-replaced elements</a>
<li><a href="#inline-replaced"><span class=secno>15.2. </span>Inline or
floating, replaced elements</a>
<li><a href="#blockwidth"><span class=secno>15.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>15.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>15.5. </span>‘<code class=property>Inline-block</code>’
or floating, non-replaced elements</a>
<li><a href="#abs-non-replaced-width"><span class=secno>15.6.
</span>Absolutely positioned, non-replaced elements</a>
<li><a href="#abs-replaced"><span class=secno>15.7. </span>Absolutely
positioned, replaced elements</a>
<li><a href="#block-level-replaced-elements-in-normal-"><span
class=secno>15.8. </span>Block-level, replaced elements in normal
flow</a>
<li><a href="#floating-non-replaced-elements"><span class=secno>15.9.
</span>Floating, non-replaced elements</a>
<li><a href="#root-height"><span class=secno>15.10. </span>Auto heights
for flow roots</a>
</ul>
<li><a href="#the-float-property"><span class=secno>16. </span>The float
property</a>
<ul class=toc>
<li><a href="#introduction-to-floats"><span class=secno>16.1.
</span>Introduction to floats</a>
<li><a href="#rules-for-positioning-floats"><span class=secno>16.2.
</span>Rules for positioning floats</a>
</ul>
<li><a href="#the-clear-property"><span class=secno>17. </span>The clear
property</a>
<li><a href="#the-clear-after-property"><span class=secno>18. </span>The
clear-after property</a>
<li><a href="#overflow0"><span class=secno>19. </span>Overflow</a>
<ul class=toc>
<li><a href="#overflow"><span class=secno>19.1. </span>The overflow,
overflow-x and overflow-y properties</a>
</ul>
<li><a href="#the-visibility-property"><span class=secno>20. </span>The
visibility property</a>
<li><a href="#the-alignment-property"><span class=secno>21. </span>The
alignment property</a>
<li><a href="#the-child-align-property"><span class=secno>22. </span>The
child-align property</a>
<li><a href="#stacking-contexts"><span class=secno>23. </span>Stacking
contexts</a>
<ul class=toc>
<li><a href="#definitions"><span class=secno>23.1.
</span>Definitions</a>
<li><a href="#painting-order"><span class=secno>23.2. </span>Painting
order</a>
<li><a href="#notes"><span class=secno>23.3. </span>Notes</a>
</ul>
<li><a href="#the-float-displace-and-indent-edge-reset"><span
class=secno>24. </span>The ‘<code
class=property>float-displace</code>’ and ‘<code
class=property>indent-edge-reset</code>’ properties
[alternative 1]</a>
<ul class=toc>
<li><a href="#the-float-displace-property"><span class=secno>24.1.
</span>The ‘<code class=property>float-displace</code>’
property</a>
<li><a href="#the-indent-edge-reset-property"><span class=secno>24.2.
</span>The ‘<code class=property>indent-edge-reset</code>’
property</a>
</ul>
<li class=no-num><a href="#the-float-displace-property-alternative2">The
‘float-displace’ property [alternative 2]</a>
<li class=no-num><a href="#the-float-displace-property-alternative3">The
‘float-displace’ property [alternative 3]</a>
<li><a href="#conformance"><span class=secno>25. </span>Conformance</a>
<li><a href="#acknowledgments"><span class=secno>26.
</span>Acknowledgments</a>
<li class=no-num><a href="#references">References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references">Normative
references</a>
<li class=no-num><a href="#informative-references">Informative
references</a>
</ul>
<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="#ref-CSS3CASCADE"
rel=biblioentry>[CSS3CASCADE]<!--{{CSS3CASCADE}}--></a> and “Media” by
the Media Queries specification <a href="#ref-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="#ref-CSS-WRITING-MODES-3"
rel=biblioentry>[CSS-WRITING-MODES-3]<!--{{!CSS-WRITING-MODES-3}}--></a>
– switch between vertical and horizontal text, properties <dfn
id=writing-mode>writing-mode</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="#ref-CSS3SYN"
rel=biblioentry>[CSS3SYN]<!--{{!CSS3SYN}}--></a> – syntax of properties
and values
<li><cite>CSS Values and Units Module</cite> <a href="#ref-CSS3VAL"
rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a> – definitions of value
types <dfn id=ltnumbergt><var><number></var></dfn>, <dfn
id=ltpercentagegt><var><percentage></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="#ref-CSS-TEXT-3"
rel=biblioentry>[CSS-TEXT-3]<!--{{!CSS-TEXT-3}}--></a> – inline layout
and definition of <dfn id=line-box.>line box.</dfn>
<li><cite>CSS Generated and Replaced Content module</cite> <a
href="#ref-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="#ref-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="#ref-CSS3UI"
rel=biblioentry>[CSS3UI]<!--{{!CSS3UI}}--></a> – defines <dfn
id=box-sizing>box-sizing</dfn>
<li><cite>CSS 2D Transforms</cite> <a href="#ref-CSS3-2D-TRANSFORMS"
rel=biblioentry>[CSS3-2D-TRANSFORMS]<!--{{!CSS3-2D-TRANSFORMS}}--></a>
– defines <dfn id=transform>transform</dfn>
<li><cite>CSS Display Module</cite> <a href="#ref-CSS-DISPLAY-3"
rel=biblioentry>[CSS-DISPLAY-3]<!--{{!CSS-DISPLAY-3}}--></a> – defines
<dfn id=display>display</dfn>
</ul>
<h2 id=introduction-amp-definitions><span class=secno>3.
</span>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 ‘<a href="#margin"><code
class=property>margin</code></a>’ to ‘<a href="#fill"><code
class=css>fill</code></a>’. ‘<a href="#fill"><code
class=css>Fill</code></a>’ is similar to ‘<code
class=css>auto</code>’, but allowed to be negative:
<pre>P {margin: 1em fill}</pre>
<li>Setting a property ‘<a href="#alignment"><code
class=property>alignment</code></a>’ on the element to center:
<pre>P {alignment: center}</pre>
<li>Setting a property ‘<a href="#child-align"><code
class=property>child-align</code></a>’ on the parent of the element to
center:
<pre>DIV {child-align: middle}</pre>
<li>Rely on grid templates <a href="#ref-CSS3LAYOUT"
rel=biblioentry>[CSS3LAYOUT]<!--{{CSS3LAYOUT}}--></a>. 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 <a
href="#horizontal">horizontal</a> 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 ‘<a href="#width"><code
class=property>width</code></a>’ property, but with the ‘<code
class=property>grid-columns</code>’ property (or the ‘<code
class=property>grid</code>’ shorthand). In the example below the
width is set to ‘<code class=property>fit-content</code>’:
<pre>P {grid: * fit-content * ". @ ."}</pre>
<p>To vertically center the single child of a <a
href="#vertical.">vertical</a> 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 ‘<a href="#height"><code class=property>height</code></a>’,
but with ‘<code class=property>grid-rows</code>’ (or the ‘<code
class=property>grid</code>’ 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 ‘<a href="#overflow1"><code
class=property>overflow</code></a>’ to anything else than ‘<code
class=property>visible</code>’ (and ‘<a href="#height"><code
class=property>height</code></a>’ to ‘<code
class=property>auto</code>’). 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 ‘<a href="#clear-after"><code
class=property>clear-after</code></a>’.
<li>Use the value ‘<code class=css>shrink-wrap</code>’ (or some other
name, e.g., ‘<code class=css>contain</code>’) on ‘<a
href="#height"><code class=property>height</code></a>’ (and ‘<a
href="#width"><code class=property>width</code></a>’, in case of
vertical text) to make an element into a <a href="#flow-root"><em>flow
root.</em></a> 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 ‘<a
href="#height"><code class=property>height</code></a>’ is due to IanH
2004-02-29]
<li>The same, but only allow the new keyword on the ‘<a
href="#min-height"><code class=property>min-height</code></a>’ and
‘<a href="#min-width"><code class=property>min-width</code></a>’
properties. [The idea to add the functionality to ‘<a
href="#min-height"><code class=property>min-height</code></a>’ is due
to Fantasai, 2012-09]
<li>A new value ‘<code class=css>container</code>’ on ‘<a
href="#display"><code class=property>display</code></a>’. This doesn't
allow a ‘<code class=css>list-item</code>’ 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 ‘<code class=property>top</code>’ moves the top down by half
the container's height, the ‘<a href="#transform"><code
class=property>transform</code></a>’ 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 ‘<code class=css>display:
flex</code>’, ‘<code class=css>flex-direction: column</code>’ and
‘<code class=css>justify-content: center</code>’ 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 ‘<code class=property>vertical-align</code>’ 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 ‘<code class=property>vertical-align</code>’ on a new
type of box called ‘<code class=css>container</code>’. (The main
function of ‘<code class=css>container</code>’ is to contain its
floating descendants.) This wouldn't allow a ‘<code
class=css>list-item</code>’, a ‘<code
class=css>table-caption</code>’ or an ‘<code
class=property>inline-block</code>’‘<code class=css> to center its
content.</code>’)
<li>Setting ‘<a href="#margin"><code
class=property>margin</code></a>’ to ‘<a href="#fill"><code
class=css>fill</code></a>’:
<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 <a href="#ref-CSS3LAYOUT"
rel=biblioentry>[CSS3LAYOUT]<!--{{CSS3LAYOUT}}--></a>. 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 ‘<code class=property>vertical-align</code>’ applies
to slots, then that also vertically centers the contents of an element.
(This centers horizontally if the element is <a
href="#vertical.">vertical,</a> because ‘<code
class=property>vertical-align</code>’ 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 <a
href="#horizontal">horizontal</a> 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 <a href="#ref-CSS-PAGE-FLOATS"
rel=biblioentry>[CSS-PAGE-FLOATS]<!--{{CSS-PAGE-FLOATS}}--></a> 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 (‘<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="#ref-CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>, 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 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 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 <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 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 id=box-tree. 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
id=contains>contains</dfn> a box <var>B</var> it means <var>B</var> is a
child of <var>A</var> in the <a href="#box-tree."><em>box tree.</em></a>
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
alt="Each generated box in the rendering has a link to the element that generated it."
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 <span class=issue>[rewrite the following
sentence?]</span> one block-level box for the <code>ul</code> element,
containing two block-level boxes for the two <code>li</code> elements,
each of which has one line box (i.e., one line of text). Both line boxes
contain two inline-level boxes: one that contains the list bullet and one
that contains the text.
<p>Note how the <code>li</code> is transformed into multiple boxes,
including one that contains “generated content,” viz., the list
bullet, which is not present in the source document.
<p>If the document is rendered in a narrow window, it may be that the
<code>li</code> elements get transformed into even more boxes, because
the text requires multiple lines. And if the document is rendered on
paper or in multiple columns, it may be that a page break falls in the
middle of the <code>ul</code> element, so that it is not transformed into
a single block-level box, but into two smaller ones, each on a different
page or column.
</div>
<p>Each box belongs to exactly one element. It is either <a
href="#generates" title="generated box">generated</a> directly by the
element, or it is an <a href="#anonymous-box"><em>anonymous box,</em></a>
which has been inserted to ensure that every box and its parent are of
mutually compatible types as defined by the layout rules of CSS. An
anonymous box is defined to belong to whichever element generates the
box's closest element-generated ancestor box. When we need to be precise,
we say that the anonymous box is <dfn id=induced>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 <a href="#ref-CSS3CASCADE"
rel=biblioentry>[CSS3CASCADE]<!--{{!CSS3CASCADE}}--></a> 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 ‘<a href="#display"><code
class=property>display</code></a>’ 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 <a href="#ref-CSS3CASCADE"
rel=biblioentry>[CSS3CASCADE]<!--{{!CSS3CASCADE}}--></a>, 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 ‘<a
href="#float"><code class=property>float</code></a>’ is not ‘<code
class=css>none</code>’, and a “positioned box” is a box whose
computed value of ‘<code class=property>position</code>’ is not
‘<code class=css>static</code>’. However, terms such as
<em>block-level box,</em> <a href="#block-container-box"><em>block
container box</em></a> 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
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 of adjacent boxes are
also subject to <a href="#collapse."><em
title=collapse>collapsing</em></a> (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 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 <dfn id=absent
title="absent|padding!!absent|border!!absent">“absent”</dfn> on some
side of the box, that 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="#ref-CSS3BG"
rel=biblioentry>[CSS3BG]<!--{{CSS3BG}}--></a> or a shape <a
href="#ref-CSS3-EXCLUSIONS"
rel=biblioentry>[CSS3-EXCLUSIONS]<!--{{CSS3-EXCLUSIONS}}--></a>.
<p>We say that a box or element is <dfn id=horizontal>horizontal</dfn> if
its ‘<a href="#writing-mode"><code
class=property>writing-mode</code></a>’ property is ‘<code
class=css>horizontal-tb</code>’, otherwise it is <dfn
id=vertical.>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>‘<code class=css>writing-mode: horizontal-tb</code>’
<th>‘<code class=css>writing-mode: vertical-rl</code>’
<th>‘<code class=css>writing-mode: vertical-lr</code>’
<tbody>
<tr>
<th>‘<code class=css>direction: ltr</code>’
<td>
<p>Text is written from left to right and paragraphs grow downwards
<p><img alt="" class=small src=horizontal.png>
<td>
<p>Text is written top to bottom and paragraphs grow to the left