-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathvisuren.src
More file actions
2066 lines (1705 loc) · 77.9 KB
/
visuren.src
File metadata and controls
2066 lines (1705 loc) · 77.9 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.0 Transitional//EN">
<html lang="en">
<!-- $Id: visuren.src,v 2.28 1998-03-15 00:01:56 ijacobs Exp $ -->
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<TITLE>Visual rendering model</TITLE>
</HEAD>
<BODY>
<H1 align="center"><a name="visual-rendering-model">Visual rendering model</a></H1>
<H2>Introduction to the visual rendering model</H2>
<P>This chapter describes the <span class="index-def" title="visual
rendering model">visual rendering model</span>, how user agents
process the <a href="conform.html#doctree">document tree</a> for
visual <a href="media.html">media</a>.
<P>In the visual rendering model, each element in the document tree
generates zero or more <a href="#box-model">rectangular boxes</a> that
are then rendered. Some boxes belong to the "normal flow" of boxes
while others are "outside the flow". A box in the normal flow has a
<span class="index-def" title="preceding box"> <a
name="preceding-box"><dfn>preceding box</dfn></a></span> in the normal
flow (unless it is the first box) and a <span class="index-def"
title="preceding box"> <a name="following-box"><dfn>following
box</dfn></a></span> in the normal flow (unless it is the last box).
<!-- Is a "preceding box" one that is generated by a "preceding
element"? (see conform.src for "preceding element") -IJ -->
<P>Most boxes establish a <span class="index-inst" title="containing
block"><a href="visudet.html#containing-block">containing
block</a></span> whose edges serve as references for the layout of
descendant boxes (see the <a href="visudet.html">next chapter</a> for
details). In the CSS visual rendering model, a box establishes
reference edges for its descendants and is itself positioned with
respect to its containing block. A box is not confined by its
containing block -- it is positioned with respect to its edges and may
even <a href="visufx.html#overflow">overflow</a> those edges. When a
box is <a href="#floats">floated</a> inside a containing block, layout
of boxes in the containing block is also affected by the edges of
those floating boxes.
<P>The <a href="#box-model">box model</a> describes the generation of
boxes. The layout of these boxes is governed by:</p>
<ul>
<li><a href="#box-dimensions">box dimensions</a> and <a
href="#box-gen">type</a>.
<li><a href="#positioning-scheme">positioning scheme</a>
(normal, float, and absolute positioning models).
<li>relationships between elements
in the <a href="conform.html#doctree">document tree.</a>
<li>external information (e.g., viewport size, intrinsic
dimensions of images, etc.).
</ul>
<P>The properties defined in this chapter apply to both <a
href="media.html#continuous-media-group">continuous media</a> and <a
href="media.html#paged-media-group">paged media</a>. However, the
meanings of the <a href="visudet.html#margin-properties">margin
properties</a> vary when applied to paged media (see the <a
href="page.html#page-model">page model</a> for details).
<P>The <a href="visudet.html">next chapter</a> supplies the details
of the visual rendering model. However, the model does not specify all
aspects of formatting (e.g., it does not specify a letter-spacing
algorithm). <a href="conform.html#conformance">Conforming user
agents</a> may behave differently for those formatting issues not
covered by this specification.
<h3>The viewport</h3>
<P>User agents for <a
href="media.html#continuous-media-group">continuous media</a>
generally offer users a <span class="index-def" title="viewport"><a
name="viewport"><dfn>viewport</dfn></a></span> (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="visudet.html#initial-containing-block">initial containing
block</a>). When the viewport is smaller than the document's
containing block, the user agent should offer a scrolling mechanism.
There is at most one viewport per <a
href="intro.html#canvas">canvas</a>, but user agents may offer users
several views of a document.
<H2><a name="box-model">The box model</a></H2>
<P>The CSS box model describes how rectangular boxes are generated for
elements in the <a href="conform.html#doctree">document
tree</a>. The <A href="page.html">page box</A> is a special kind of
box that is described in detail on the section on <A
href="page.html">paged media</a>.
<H3><a name="box-gen">Controlling box generation:</a> the <span
class="propinst-display">'display'</span> property</H3>
The <span class="propinst-display">'display'</span> property
determines whether an element generates a box, and if so, what type of
box it generates.
<!-- #include src=properties/display.srb -->
<!-- What about BUTTON? -->
<P><span class="index-def" title="block-level
element"><a name="block-level"><dfn>Block-level elements</dfn></a></span> are those elements of
the document language that, by default, are formatted visually as
blocks (e.g., paragraphs). Several values of the <span
class="propinst-display">'display'</span> property make an element
block-level: 'block', 'list-item', 'compact' and 'run-in' (part of the
time; see <a href="#compact">compact</a> and <a href="#run-in">run-in boxes</a>),
and 'table'.
<P>Most block-level elements generate <a name="block-box">block
boxes</a>, but some elements also produce inline <a
href="#anonymous">anonymous</a> boxes.
<P><span class="index-def" title="inline-level element">
<a name="inline-level"><dfn>Inline-level
elements</dfn></a></span> are those elements of the document language that
do not form new blocks of content (e.g., emphasized pieces of text
within a paragraph, inline images,
etc.). Several values of the <span
class="propinst-display">'display'</span> property make an element
inline: 'inline', 'inline-table',
'compact' and 'run-in' (part of the time; see <a
href="#compact">compact</a> and <a href="#run-in">run-in boxes</a>).
Inline-level elements generate <a name="inline-box">inline boxes</a>.
<P>A block box acts as a <a
href="visudet.html#containing-block">containing block</a> for its
descendant boxes, which may be both block boxes and inline boxes.
(One may think of anonymous block boxes springing into existence to
surround "naked" inline content between block content). Sibling block
boxes participate in a <a href="#block-formatting">block formatting
context</a>.
<P>An <a href="#inline-box">inline</a> box participates in an <a
href="#inline-formatting">inline formatting context</a> with its
siblings and children.
<P>The values of this property have the following meanings:</P>
<dl>
<dt><span class="index-def" title="'block', definition of"><a
name="value-def-block"><strong>block</strong></a></span>
<dd>This value causes an element to generate a block box.
<dt><span class="index-def" title="'inline', definition of"><a
name="value-def-inline"><strong>inline</strong></a></span>
<dd>This value causes an element to generate an inline
box.
<dt><span class="index-def" title="'list-item', definition of"><a
name="value-def-list-item"><strong>list-item</strong></a></span>
<dd>This value causes an element to generate a <a
href="#block-box">block</a> box that also has a
list-item marker box. For example, in HTML, the LI
element will typically have this <span
class="propinst-display">'display'</span> value.
For information about lists and examples of list formatting,
please consult the section on <a href="lists.html">lists</a>.
<dt><span class="index-def" title="marker', definition of"><a
name="value-def-marker"><strong>marker</strong></a></span> <dd>This
value declares <a href="generate.html">generated content</a> before or
after a box to be an alignable marker. This value may only be used
with the <a href="generate.html#before-after-content">:before and
:after pseudo-elements</a>. Please consult the section on <a
href="generate.html#markers">markers</a> for more information.
<dt><span class="value-def-none"><strong>none</strong></span>
<dd><span class="index-def" title="'none'::as display value">This
value</span> causes an element to generate <b>no</b> boxes in the <a
href="intro.html#rendering-structure">rendering structure</a> (i.e.,
the element has no effect on layout). Descendant elements do not
generate any boxes either; this behavior <strong>cannot ever</strong> be
overridden by setting the <span
class="propinst-display">'display'</span> property on the descendants.
<P>Please note that a display of 'none' does not create an invisible
box; it creates no box at all. CSS includes mechanisms that enable an
element to generate boxes in the rendering structure that affect
formatting but are not visible themselves. Please consult the section
on <a href="visufx.html#visibility">visibility</a> for details.
<dt><span class="index-def" title="'run-in', definition of"><a
name="value-def-run-in"><strong>run-in</strong></a></span>
and <span class="index-def" title="'compact', definition of"><a
name="value-def-compact"><strong>compact</strong></a></span>
<dd>These values create a box that is block-level
or inline-level, depending on context. These values are described below.
<dt><span class="index-inst" title="'table'"><a
name="value-inst-table"><strong>table</strong></a></span>, <span
class="index-inst" title="'inline-table'"><a
name="value-inst-inline-table"><strong>inline-table</strong></a></span>, <span
class="index-inst" title="'table-row-group'"><a
name="value-inst-table-row-group"><strong>table-row-group</strong></a></span>,
<span class="index-inst" title="'table-column-group'"><a
name="value-inst-table-column-group"><strong>table-column-group</strong></a></span>,
<span class="index-inst" title="'table-header-group'"><a name="value-inst-table-header-group"><strong>table-header-group</strong></a></span>,
<span class="index-inst" title="'table-footer-group'"><a name="value-inst-table-footer-group"><strong>table-footer-group</strong></a></span>,
<span class="index-inst" title="'table-row'"><a
name="value-inst-table-row"><strong><strong>table-row</strong></strong></a></span>, <span
class="index-inst" title="'table-cell'"><a
name="value-inst-table-cell"><strong><strong>table-cell</strong></strong></a></span>, and <span
class="index-inst" title="'table-caption'"><a
name="value-inst-table-caption"><strong>table-caption</strong></a></span>
<dd>These values cause an element to behave like a table element
(subject to restrictions described in the chapter on <a
href="tables.html">tables</a>).
</dl>
<P>Note that although the <a href="cascade.html#initial-value">initial
value</a> of <span class="propinst-display">'display'</span> is
'inline', rules in the user agent's <a
href="cascade.html#default-style-sheet">default style sheet</a> may <a
href="cascade.html">override</a> this value. See the <a
href="sample.html">sample style sheet</a> for HTML 4.0 in the
appendix.
<div class="example"><P>
<P>Here are some examples of the <span
class="propinst-display">'display'</span> property:
<PRE>
P { display: block }
EM { display: inline }
LI { display: list-item }
IMG { display: none } /* Don't display images */
</PRE>
</div>
<P><span class="index-inst" title="conformance"><a
href="conform.html#conformance">Conforming HTML user agents</a></span>
may <span class="index-inst" title="ignore"><a
href="syndata.html#ignore">ignore</a></span> the <span
class="propinst-display">'display'</span> property when specified in
author and user style sheets but must specify a value for it in the <a
href="cascade.html#default-style-sheet">default style sheet</a>.
<p>Properties apply to run-in and compact boxes based on their
final status (inline-level or block-level). For example, the <span
class="propinst-white-space">'white-space'</span> property only
applies if the box behaves like a block box.
<H4><a name="compact">'Compact' boxes</a></h4>
<P>A <span class="index-def" title="compact box"><a name="compact"><dfn>compact
box</dfn></a></span> behaves as follows:</p>
<ul>
<li>If a <a href="#block-box">block</a> box (that does not
float and is not absolutely positioned) <a
href="#following-box">follows</a> the compact box, the compact box is
formatted like a one-line inline box.
The resulting box width is compared to one of the side margins of
the block box.
The choice of left or right margin is determined
by the <span class="propinst-direction">'direction'</span> specified
for the element producing the <a href="visudet.html#containing-block">
containing block</a> for the compact box and following box.
If the inline box width is less
than or equal to the margin, the inline box is positioned in the
margin as described immediately below.
<li>Otherwise, the compact box behaves like a block box.
</ul>
<P>The compact box is positioned in the margin as follows: it is
outside (to the left or right) of the first <a href="#line-box">line
box</a> of the block, but it affects the calculation of that <a
href="visudet.html#box-height">line box's height</a>. The <span
class="propinst-vertical-align">'vertical-align'</span> property of
the compact box determines the vertical position of the compact box
relative to that line box. The horizontal position of the compact box
is always in the margin of the block box, as far to the outside
as possible.
<P>An element that cannot be rendered on one line cannot be placed in
the margin of the following block. For example, a 'compact' element in
HTML that contains a <BR> element will always be rendered as a
block box (assuming the default style for BR, which inserts a
newline). For placing multi-line texts in the margin, the <span
class="propinst-float">'float'</span> property is often more adequate.
<div class="html-example">
<p>The following example illustrates a compact box.
<pre>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>A compact box example</TITLE>
<STYLE type="text/css">
DT { display: compact }
DD { margin-left: 4em }
</STYLE>
</HEAD>
<BODY>
<DL>
<DT>Short
<DD><P>Description goes here.
<DT>too long for the margin
<DD><P>Description goes here.
</DL>
</BODY>
</HTML>
</pre>
</div>
<P>This example might be rendered as:
<pre>
<b>short</b> Description goes here
<b>too long for the margin</b>
Description goes here
</pre>
<p>The <span class="propinst-text-align">'text-align'</span> property
can be used to align the compact element inside the margin: against
the left edge of the margin ('left'), against the right edge
('right'), or centered in the margin ('center'). The value 'justify'
doesn't apply, and is handled as either 'left' or 'right', depending
on the <span class="propinst-direction">'direction'</span> of the
block-level element in whose margin the compact element is
rendered. ('left' if the direction is 'ltr', 'right' if it is 'rtl'.)
<P>Please consult the section on
<a href="generate.html#compact-run-in-gen">generated content</a>
for information about how compact boxes interact with generated
content.
<H4><a name="run-in">'Run-in' boxes</a></h4>
<P>A <span class="index-def" title="run-in box"><dfn>run-in
box</dfn></span> behaves as follows:</p>
<ul>
<li>If a <a href="#block-box">block</a>
box (that does not float and is not
absolutely positioned) <a href="#following-box">follows</a> the run-in
box, the run-in box behaves like an inline child of the block box.
<li>Otherwise, the run-in box behaves like a block box.
</ul>
<p>A 'run-in' box is useful for run-in headers, as
in this example:
<div class="html-example">
<P>
<pre>
<HTML>
<HEAD>
<TITLE>A run-in box example</TITLE>
<STYLE type="text/css">
H3 { display: run-in }
</STYLE>
</HEAD>
<BODY>
<H3>A run-in heading.</H3>
<P>And a paragraph of text that
follows it.
</BODY>
</HTML>
</pre>
</div>
<p>This example might be rendered as:
<pre>
<b>A run-in heading.</b> And a
paragraph of text that
follows it.
</pre>
<p>The properties of the run-in element are inherited from its
parent in the source tree, not from the block box it visually
becomes part of.
<P>Please consult the section on
<a href="generate.html#compact-run-in-gen">generated content</a>
for information about how run-in boxes interact with generated
content.
<H3><a name="box-dimensions">Box dimensions</a></H3>
<P>Each box has a
<span class="index-def" title="box::content|content::of a box">
<a name="box-content-area"><dfn>content area</dfn></a></span> (e.g.,
text, an image, etc.) and optional surrounding
<span class="index-def" title="box::padding|padding::of a box">
<a name="box-padding-area"><dfn>padding</dfn></a></span>,
<span class="index-def" title="box::border|border::of a box">
<a name="box-border-area"><dfn>border</dfn></a></span>, and
<span class="index-def" title="box::margin|margin::of a box">
<a name="box-margin-area"><dfn>margin</dfn></a></span> areas; the size
of each area is specified by properties defined in the <a
href="visudet.html">next chapter</a>. The following diagram shows
how these areas relate and the terminology used to refer to pieces of
margin, border, and padding:</P>
<P><img src="./images/boxdim.gif"
alt="Image illustrating the relationship between content, padding, borders, and margins."></P>
<P>The margin, border, and padding can be broken down into left,
right, top, and bottom segments (e.g., in the diagram, "LM" for left
margin, "RP" for right padding, "TB" for top border, etc.
<P>The perimeter of each of the four areas (content, padding, border,
and margin) is called an "edge", so each box has four edges:</P>
<dl>
<dt><span class="index-def"
title="content edge"><a name="content-edge"><strong>content edge</strong></a></span>
or <span class="index-def" title="inner edge"><a name="inner-edge"><strong>inner edge</strong></a></span>
<dd>The content edge surrounds the element's <a href="conform.html#rendered-content">rendered content</a>.
<dt><span class="index-def" title="padding edge"><a name="padding-edge"><strong>padding edge</strong></a></span>
<dd>The padding edge surrounds the box padding. If the padding
has 0 width, the padding edge is the same as the content edge.
The padding edge of a box defines the edges of the
<a href="visudet.html#containing-block">containing block</a> established by the box.
<dt><span class="index-def" title="border edge"><a name="border-edge"><strong>border edge</strong></a></span>
<dd>The border edge surrounds the box border. If the border
has 0 width, the border edge is the same as the padding edge.
<dt><span class="index-def" title="margin edge"><a name="margin-edge"><strong>margin edge</strong></a></span>
or <span class="index-def" title="outer edge"><a name="outer-edge"><strong>outer
edge</strong></a></span>
<dd>The margin edge surrounds the box margin. If the margin
has 0 width, the margin edge is the same as the border edge.
</dl>
<P>Each edge may be broken down into a left, right, top, and bottom
edge.
<!-- Say something about top/bottom behavior during layout
of block-level and abs. positioned boxes -IJ -->
<P>The dimensions of the content area of a box -- the <span
class="index-def" title="box::content width"><a
name="content-width"><dfn>content width</dfn></a></span> and <span
class="index-def" title="box::content height"><a
name="content-height"><dfn>content height</dfn></a></span> -- may be
established in one of several ways:</p>
<dl>
<dt><em>Width and height properties set explicitly</em>
<dd> The <span class="propinst-width">'width'</span> and
<span class="propinst-height">'height'</span> properties specify
a dimension explicitly. Except for <a href="tables.html">table</a>
cells, specified values other than 'auto' for
<span class="propinst-width">'width'</span> and
<span class="propinst-height">'height'</span> cannot be overridden
for a generated box.
<dt><em>block box widths are calculated top-down</em>
<dd>The width of a block box
is given by the width of its
containing block and the box's margins, borders, and padding.
Please consult the sections on <a
href="visudet.html#box-width">box width calculations</a> for details.
<dt><em>Inline box widths are calculated bottom-up</em>
<dd>The width of an inline box is given by its
<a href="conform.html#rendered-content">rendered content</a>.
Please consult the sections on <a
href="visudet.html#box-width">box width calculations</a> for details.
<dt><em>block box heights are calculated bottom-up</em>
<dd>Block level boxes grow to the size of the boxes
they contain.
Please consult the section on <a
href="visudet.html#box-height">box height calculations</a> for
details.
<dt><em>Inline box heights are given by the <span
class="propinst-line-height">'line-height'</span> property</em>
<dd>Please consult the section on <a
href="visudet.html#box-height">box height calculations</a> for
details.
<dt><em>Line heights depend on inline box heights and alignment</em>
<dd>Please consult the section on <a
href="visudet.html#line-height">line height calculations</a> for
details.
<dt><em><a name="intrinsic-dim">Intrinsic dimension of replaced
content</a></em>
<dd>The <a href="conform.html">rendered content</a> of a <a
href="conform.html#replaced-element">replaced element</a> may have
"intrinsic dimensions" that user agents use as the <a
href="cascade.html#computed-value">computed</a> content
width and height (e.g., the unscaled width and height of an included
image). If the intrinsic dimensions are overridden, the
replaced content is scaled by the user agent.
When scaling an element with intrinsic dimensions,
the aspect ratio is preserved
if values for the <span class="propinst-width">'width'</span> and
<span class="propinst-height">'height'</span> properties are set to
'auto'.
<dt><em>Hybrid calculations</em>
<dd>The dimension of a table cell is determined by both the cell's
contents and the surrounding available space.
</dl>
<P>The <span class="index-def" title="box::width"><a
name="the-box-width"><dfn>box width</dfn></a></span> (<span
class="index-def" title="box::height"><a
name="the-box-height"><dfn>height</dfn></a></span>) is
given by the sum of the content width (height), the
padding, the border, and the margin.
<P>Note that although top and bottom margins, borders, and padding
specified for <a href="#inline-level">inline-level</a> elements do
<em>not</em> enter into <a href="visudet.html#line-height">line box
height calculations</a>, but are visible (inside and outside line
boxes).
<P>Note that there are no properties to set the color of margins and
padding; margins are always transparent and padding areas always use
the background of the element itself. The background of an element
extends to the padding edge of the box it generates.
<H3><a name="mpb-examples">Example of margins, padding, and borders</a></H3>
This example illustrates how margins, padding, and borders
interact. The example HTML document:
<PRE class="html-example">
<HTML>
<HEAD>
<STYLE type="text/css">
UL {
background: orange;
margin: 12px 12px 12px 12px;
padding: 3px 3px 3px 3px;
/* No borders set */
}
LI {
color: white; /* text color is white */
background: blue; /* Content, padding will be blue */
margin: 12px 12px 12px 12px;
padding: 12px 0px 12px 12px; /* Note 0px padding right */
list-style: none /* no glyphs before a list item */
/* No borders set */
}
LI.withborder {
border-style: dashed;
border-width: medium; /* sets border width on all sides */
border-color: green;
}
</STYLE>
</HEAD>
<BODY>
<UL>
<LI>First element of list
<LI class="withborder">Second element of list is longer
to illustrate wrapping.
</UL>
</BODY>
</HTML>
</PRE>
<P>results in a <a href="conform.html#doctree">document tree</a> with
(among other relationships) a UL element that has two LI
children.
<P>The first of the following diagrams illustrates what this example
would produce. The second illustrates the relationship between the
margins, padding, and borders of the UL elements and those of its
children LI elements.</P>
<P><img src="./images/boxdimeg.gif"
alt="Image illustrating how parent and child margins, borders,
and padding relate."></p>
<P>Note that:</p>
<ul>
<li>The <a href="#content-width">content width</a> for each LI box is
calculated top-down; the <a href="visudet.html#containing-block">containing
block</a> for the each LI box is the box generated by the UL element.
<li>The height of each LI box is given by its <a
href="#content-height">content height</a>, plus padding, borders, and
margins. Note that vertical margins between the LI boxes <a
href="visudet.html#collapsing-margins">collapse.</a>
<li>The right padding of the LI boxes has been set to zero width
(the <span class="propinst-padding">'padding'</span> property). The
effect is apparent in the second illustration.
<li>The foreground color of the LI boxes has been set to white for
legibility against a blue background (the <span
class="propinst-color">'color'</span> property).
<li>The margins of the LI boxes are transparent -- margins are always
transparent -- so the background color of the UL boxes (orange) shines
through them. However, the (blue) background of the LI boxes is also
used for the LI padding.
<li>The second LI element specifies a dashed border (the
<span class="propinst-border-style">'border-style'</span> property).
</ul>
<h2><a name="positioning-scheme">Positioning schemes</a></h2>
<P>In CSS2, a box may be laid out according to three <span
class="index-def" title="positioning scheme"><dfn>positioning
schemes</dfn></span></p>
<ol>
<li><a href="#normal-flow">Normal flow</a>. The normal
flow includes <a href="#block-formatting">block formatting</a>
of <a href="#block-level">block level</a> elements,
<a href="#inline-formatting">inline formatting</a>
of <a href="#inline-level">inline-level</a> elements, <a
href="#relative-positioning">relative positioning</a> of
block-level or inline-level elements, and positioning of
<a href="#compact">compact</a> and <a href="#run-in">run-in</a> boxes.
<li><a href="#floats">Floats</a>. The floating model translates
a box's position to the left or right of where
it would normally appear in the flow. For instance, authors may
float paragraph boxes in order to place them side-by-side.
<li><a href="#absolute-positioning">Absolute positioning</a>. Authors
may specify the absolute position of a box (with respect to
a containing block).
</ol>
<P>The primary difference between a floating box and one that is
absolutely positioned is that absolute positioning has no impact on
the flow of later siblings; later siblings are laid out as though the
absolutely positioned box did not exist at all. Later siblings of
floating boxes flow with respect to the final position of the floating
box.
<h3><a name="choose-position">Choosing a positioning scheme:</a> <span
class="propinst-position">'position'</span> property</h3>
<P>The <span class="propinst-position">'position'</span> and <span
class="propinst-float">'float'</span> properties determine which CSS2
positioning algorithms are used to calculate the coordinates of a box.
<!-- #include src=properties/position.srb -->
<P>The values of this property have the following meanings:</P>
<dl>
<dt><strong>normal</strong>
<dd>The box coordinates are calculated according to the
<a href="#normal-flow">normal flow</a>.
<dt><strong>relative</strong>
<dd>The box coordinates are calculated according to the <a
href="#normal-flow">normal flow</a>, then the box is
offset <a href="#relative-positioning">relative</a> to its normal
position. Note that the position of the <a href="#following-box">
following box</a> is established independently of the offset.
<dt><strong>absolute</strong>
<dd> The box coordinates (and possibly size) are calculated
in <a href="#absolute-positioning">absolute</a> terms
with respect to the box's <a
href="visudet.html#containing-block">containing block</A>.
<dt><strong>fixed</strong>
<dd> The box coordinates are calculated according to the 'absolute'
model, but in addition, the box is <a
href="#fixed-positioning">fixed</a> with respect to some reference. In
the case of <a href="media.html#continuous-media-group">continuous
media</a>, the box is fixed with respect to the <a
href="#viewport">viewport</A> (and doesn't move when scrolled). In
the case of <a href="media.html#paged-media-group">paged media</a>,
the box is fixed with respect to the page, even if that page is seen
through a <a href="#viewport">viewport</A> (in the case of a
print-preview, for example). Authors may wish to specify 'fixed' in a
media-dependent way. For instance, an author may want a box to remain
at the top of the <a href="#viewport">viewport</A> on the screen, but
not at the top of each printed page. The two specifications may be
separated by using an <a href="media.html#at-media-rule">@media
rule</a>, as in:
<div class="example"><P>
<PRE>
@media screen {
H1#first { position: fixed }
}
@media print {
H1#first { position: normal }
}
</PRE>
</div>
</dl>
<div class="note"><P> <em><strong>Note.</strong> The value 'normal'
causes some user agents to <span class="index-inst" title="ignore"><a
href="syndata.html#ignore">ignore</a></span> the <span
class="propinst-left">'left'</span> and <span
class="propinst-top">'top'</span> properties. To ensure that values of
<span class="propinst-left">'left'</span> and <span
class="propinst-top">'top'</span> are taken into account, authors
should explicitly set the value of the <span
class="propinst-position">'position'</span> property to 'relative'.
</em>
</div>
<H3><a name="position-props">Box offsets</a>: <span
class="propinst-top">'top'</span>, <span
class="propinst-right">'right'</span>, <span
class="propinst-bottom">'bottom'</span>, <span
class="propinst-left">'left'</span></H3>
<P>The position of a <a href="#relative-positioning">relatively</A>
or <a href="#absolute-positioning">absolutely</A> (including <a
href="#fixed-positioning">fixed</A>) positioned box is established
by four properties:
<!-- #include src=properties/top.srb -->
<P>This property specifies how far a box's top content edge is offset below
the top edge of the box's <a href="visudet.html#containing-block">containing block</a>.
<!-- #include src=properties/right.srb -->
<P>This property specifies how far a box's right content edge is offset
to the left of the right edge of the box's <a
href="visudet.html#containing-block">containing block</a>.
<!-- #include src=properties/bottom.srb -->
<P>This property specifies how far a box's bottom content edge is offset
above the bottom of the box's <a href="visudet.html#containing-block">containing
block</a>.
<!-- #include src=properties/left.srb -->
<P>This property specifies how far a box's left content edge is offset
to the right of the left edge of the box's <a
href="visudet.html#containing-block">containing block</a>.
<P>The values for the four properties have the following meanings:</p>
<dl>
<dt><strong><span class="value-inst-length"><length></span></strong>
<dd>The offset is a fixed distance from the reference edge.
<dt><strong><span class="value-inst-percentage"><percentage></span></strong>
<dd>The offset is a percentage of the containing block's width (for <span class="propinst-left">'left'</span> or <span
class="propinst-right">'right'</span>) or height (for <span
class="propinst-top">'top'</span> and <span
class="propinst-bottom">'bottom'</span>).
<dt><strong>auto</strong>
<dd>The offset is automatically calculated based on the width and
height of the box.
<!-- define according to last CSS-P draft. 26/2/98 -->
</dl>
<P>For absolutely positioned boxes, the offsets are with respect to
the box's <a href="visudet.html#containing-block">containing
block</a>. For relatively positioned boxes, the offsets are with
respect to the outer edges of the box itself (i.e., the box is
normally positioned, then offset from that position according to
these properties).
<P>Absolutely positioned boxes do not have margins established by the
<a href="visudet.html#margin-properties">margin properties</a>, though
they do have padding and borders.
<P>For more information about the width and height of boxes, please
consult the sections on <a href="visudet.html#box-width">box width
calculations</a> and <a href="visudet.html#box-height">box height
calculations</a> respectively.
<H2><a name="normal-flow">Normal flow</a></H2>
<P>Boxes in the normal flow belong to a <span class="index-def"
title="formatting context">formatting context</span>, which may be
block or inline, but not both simultaneously.
<P><a href="#block-box">Block</a> boxes participate in a <a
href="#block-formatting">block formatting</a> context.
<P><a href="#inline-box">Inline boxes</a> participate in an <a
href="#inline-formatting">inline formatting</a> context.
<h3><a name="anonymous-block-level">Anonymous block boxes</a></h3>
<p>In a document like this:
<pre>
<DIV>
Some text
<P>Some more text
</DIV>
</pre>
<p>(and assuming the DIV and the P both have 'display: block'), the
DIV appears to have both inline content and block content. To
make it easier to define the formatting, we assume that there is an
<em><span class="index-def" title="anonymous">anonymous block box</span></em> around "Some text".
<div class="figure">
<p><img src="images/anon-block.gif" alt="diagram showing the three
boxes for the example above"> <p class="caption">Diagram showing the
three boxes, of which one is anonymous, for the example above
</div>
<p>In other words: if a block box (such as that generated for
the DIV above) has another block box inside it (such as the P
above), then we force it to have <em>only</em> block boxes
inside it, by wrapping any inline boxes in an anonymous block box.
<p>The properties of these anonymous boxes are inherited from the
enclosing non-anonymous box (in the example: the one for
DIV). Non-inherited properties have their initial value. For example,
the font of the anonymous box is inherited from the DIV, but the
margins will be 0.
<h3><a name="anonymous">Anonymous inline boxes</a></h3>
<p>In a document like this:
<pre>
<P>Some <EM>emphasized</em> text
</pre>
<p>The P generates a block box, with several inline boxes inside
it. The box for "emphasized" is an inline box generated by an inline
element (EM), but the other boxes ("Some" and "text") are inline boxes
generated by a block-level element (P). The latter are called <span
class="index-def" title="anonymous inline boxes">anonymous inline
boxes</span>, because they don't have an associated inline-level element.
<p>Such anonymous inline boxes inherit inheritable properties from
their block parent box. Non-inherited properties have their
initial value.
<p>In the example, the color of the anonymous initial boxes is
inherited from the P, but the background is transparent.
<p>If it is clear from the context which type of anonymous box is
meant, both anonymous inline boxes and anonymous block boxes are
simply called anonymous boxes in his specification.
<p>There are more types of anonymous boxes in the <a
href="tables.html#anonymous-boxes">table context</a>.
<h3><a name="block-formatting">Block formatting context</a></h3>
<P>In a block formatting context, boxes are laid out one after the
other, vertically, beginning at the top of a containing block. The
vertical distance between two sibling boxes is determined by the <span
class="propinst-margin">'margin'</span> properties. Vertical margins
between adjacent block boxes <a
href="./visudet.html#collapsing-margins">collapse</a>.
<!-- Add a statement/link here about bottom-up height calc? -IJ -->
<P>To lay out boxes horizontally in CSS2, authors may declare them to
be <a href="#inline-box">inline</a>, or position them (using <a
href="#floats">floats</a> or <a
href="#absolute-positioning">absolute</a> positioning).
<P>For information about page breaks in paged media, please consult
the section on <a href="page.html#allowed-page-breaks">allowed
page breaks</a>.
<H3><a name="inline-formatting">Inline formatting context</a></H3>
<P>In an inline formatting context, boxes are laid out horizontally,
one after the other, beginning at the top of a containing
block. Horizontal margins, borders, and padding are respected between
these boxes. They may be aligned vertically in different ways: their
bottoms or tops may be aligned, or the baselines of text within them
may be aligned. The rectangular area that contains the boxes that form
a line is called a <span class="index-def" title="line box"><a
name="line-box"><dfn>line box</dfn></a></span>. The margin between
the first inline box in a line box and the near line box edge is respected;
the same holds for the last inline box and the opposite line box
edge.
<P>The width of a line box is determined by a <A
HREF="visudet.html#containing-block">containing block</A>. The height of a line
box is determined by the rules given in the section on <a
href="visudet.html#line-height">line height calculations</a>. A line
box is always tall enough for all of the boxes it contains. However,
it may be taller than the tallest box it contains (if, for example,
boxes are aligned so that baselines line up). When the height of a
box B is less than the height of the line box containing it, the
vertical alignment of B within the line box is determined by the <span
class="propinst-vertical-align">'vertical-align'</span> property.
<P>When several inline boxes cannot fit within a single line box, they
are distributed among two or more vertically-stacked line boxes. Thus,
a paragraph is a vertical stack of line boxes. Line boxes are stacked
with no vertical separation and they never overlap.
<P>Line boxes in the same inline formatting context generally have the
same width (that of the containing block) but may vary in width if
available horizontal space is reduced due to <a
href="#floats"> floats</a>. Line boxes in the same inline
formatting context generally vary in height (e.g., one line might
contain an image while the others contain only text).
<P>When the total width of the boxes on a line is less than the width
of the line box containing them, their horizontal alignment within the
line box is determined by the <span
class="propinst-text-align">'text-align'</span> property. If that
property has the value 'justify', the user agent may stretch the
inline boxes as well.
<P>Since a box may not exceed the width of a line box, long boxes are
split into several boxes and these boxes distributed across several
line boxes. When a box is split, margins, borders, and padding have no
visual effect at the end of the first line box or at the beginning of
the next line box.
<P>Inline boxes may also be split into several boxes <em>in the same
line box</em> due to <a href="#direction">bidirectional text
processing</a>.
<div class="html-example"><P>
Here is an example of inline box construction. The following paragraph
(created by the HTML block-level element P) contains anonymous text
interspersed with the elements EM and STRONG:
<PRE>
<P>Several <EM>emphasized words</EM> appear
<STRONG>in this</STRONG> sentence, dear.</P>
</PRE>
<P>The P element generates a block box that contains five inline
boxes, three of which are anonymous:</p>
<ul>
<li>Anonymous: "Several"
<li>EM: "emphasized words"
<li>Anonymous: "appear"
<li>STRONG: "in this"
<li>Anonymous: "sentence, dear."
</ul>
<P>To format the paragraph, the user agent flows the five boxes into
line boxes. Since the parent box in normal flow acts as the containing
block for an inline box, the width of the P box determines the width
of these line boxes. If the width of P is sufficient, all the inline
boxes will fit into a single line box:
<PRE>
Several <EM>emphasized words</EM> appear <STRONG>in this</STRONG> sentence, dear.
</PRE>
<P>If the boxes do not fit within a single line box, they will
be split up and distributed across several line boxes. The previous
paragraph might be split as follows:
<PRE>
Several <EM>emphasized words</EM> appear
<STRONG>in this</STRONG> sentence, dear.
</PRE>
<P>or like this:
<PRE>
Several <EM>emphasized</EM>
<EM>words</EM> appear <STRONG>in this</STRONG>
sentence, dear.
</PRE>
</div>
<P>In the previous example, the EM box was split into two EM boxes
(call them "split1" and "split2"). Therefore, margins, borders,
padding, or text decorations have no visible effect after split1 or
before split2.
<div class="html-example"><P>
Consider the following example:
<PRE>
<HTML>
<HEAD>
<TITLE>Example of inline flow on several lines</TITLE>
<STYLE type="text/css">
EM {
padding: 2px;
margin: 1em;
border-width: medium;
border-style: dashed;
line-height: 2.4em;
}
</STYLE>
</HEAD>
<BODY>
<P>Several <EM>emphasized words</EM> appear here.</P>
</BODY>