-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathvisuren.src
More file actions
1289 lines (1009 loc) · 47.7 KB
/
visuren.src
File metadata and controls
1289 lines (1009 loc) · 47.7 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 1.43 1997-11-27 03:18:37 ian Exp $ -->
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<TITLE>Visual rendering model</TITLE>
<LINK rel="next" href="flowobj2.html">
<LINK rel="previous" href="media.html">
<LINK rel="STYLESHEET" href="style/default.css" type="text/css">
</HEAD>
<BODY>
<H1 align="center">Visual rendering model</H1>
<!-- Defined "containing block" -->
<H2>Introduction to the visual rendering model</H2>
<P>The following sections describe how user agents construct a
rendering structure.
<P>Most elements in the <a href="convent.html#doctree">document
tree</a> generate a corresponding box in the tree of rendering objects
that participates in the formatting algorithms known as the <a
href="#flow-model">visual flow model.</a> The dimensions of each
rectangular box, the relationship of the box to its parent and
children in the tree of rendering objects, and other factors all
affect how the user agent will lay out these boxes on the <a
href="media.html#canvas">canvas.</a>
<P>All elements that have text content (block or inline) generate
"anonymous" boxes in the tree of boxes. These <a
href="#anonymous">anonymous boxes</a>, which contain "chunks" of text,
inherit properties (colors, fonts, etc.) from their ancestor
boxes. By default, anonymous boxes are inline, i.e., text is laid out
horizontally. Decisions about the construction of anonymous boxes
depend on many factors (language, hyphenation, etc.) and lie outside
the scope of this specification.
<P>Elements with a value of 'none' for the <span
class="propinst-display">'display'</span> property generate no box in
the tree of rendering objects. Thus, those elements have no impact on
the positioning of any boxes.
<P>Finally, some elements in the document tree generate a box in the
tree of rendering objects but that box is invisible. It cannot be
seen, but it does participate in formatting algorithms. Please consult
the section on <a href="flowobj2.html#visibility">visibility</a> for
details.
<P>Normally, child boxes are positioned within the box of their
parent. However, a child box may extend horizontally beyond the
bounding box of its parent in certain situations. These are described
in the section on <a href="flowobj2.html#overflow">overflow</a>.
<P>CSS2 does not specify all aspects of formatting (e.g.,
letter-spacing algorithm). Conforming user agents may format
differently for situations not covered in this specification.
<H2><a name="box-model">Introduction to the box model</a></H2>
<P>The CSS box model describes the box rendering object. This object
is characterized in particular by three groups of properties: <a
href="flowobj2.html#margin-properties">margin</a>, <a
href="flowobj2.html#padding-properties">padding</a>, and <a
href="flowobj2.html#border-properties">border</a>, described below.
<P>For information on the <em>layout</em> of boxes, please consult the
section on the <a href="#flow-model">visual flow model</a>.
<P>The <A HREF="page.html">page box</A> is a special kind of box which
is described in detail on the section on <A href="page.html">paged
media</a>.
<H3><a name="box-dimensions">Box dimensions</a></H3>
<P>Each box has a core content area (e.g., text, an image, etc.) and
optional surrounding padding, border and margin areas. The following
diagram illustrates how these areas relate and defines more precise
terminology used to describe pieces of margin, border, and
padding:</P>
<img src="./images/boxdim.gif"
alt="Image illustrating the relationship between content, padding, borders, and margins.">
<P>The width (resp., height) of the <EM>box</EM> is given by the sum
of the content width (resp., height), the padding, the border, and the
margin. The size of the margin, border and padding are set with the
<a href="flowobj2.html#margin-properties">margin</a>, <a
href="flowobj2.html#padding-properties">padding</a>, and <a
href="flowobj2.html#border-properties">border</a> properties, respectively.
<P>The width of the <EM>element</EM> is the width of the content,
i.e., the distance between left inner edge and right inner edge. The
height of the element is the height of the content, i.e., the distance
from inner top to inner bottom.
<P>The <EM>outer edge</EM> is the edge of an element including its
padding, border, and margin. The <EM>inner edge</EM> is the edge of
the content only, inside any padding, border or margin.
<P>The <EM>top</EM> is the top of the object including any padding,
border and margin; it is only defined for <a
href="#inline">inline</a> and floating elements, not for
non-floating block-level elements. The <EM>inner top</EM> is the top
of the content, inside any padding, border or margin. The
<EM>bottom</EM> is the bottom of the element, outside any padding
border and margin; it is only defined for inline and <a
href="#floats">floating elements</a>, not for non-floating
<a href="#block-level">block-level</a> elements. The <EM>inner
bottom</EM> is the bottom of the element, inside any padding, border
and margin.
<P>In the following sections, we define the properties that allow
authors to set margins, padding, and borders. There are no properties
to set the color of margins and padding; margins are always
transparent and padding areas always uses the background of the
element itself.
<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>
<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>
<UL>
<LI>First element of list
<LI class="withborder">Second element of list is longer
to illustrate wrapping.
</UL>
</PRE>
<P>results in a <a href="convent.html#doctree">document
tree</a> with (among other relationships) a UL element that
has two LI children. According to the <a href="flowobj.html#flow-model">
visual rendering model</a>, the LI elements are
laid out vertically (one after the other) and form the
content of the UL.
<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>
<img src="./images/boxdimeg.gif"
alt="Image illustrating how parent and child margins, borders,
and padding relate.">
<P>Note that:</p>
<ul>
<li>The width of content for each LI element has not been specified by
the <span class="propinst-width">'width'</span> property. Therefore,
according to the rules of the <a href="flowobj2.html#box-height">box
height calculations</a>, the width allotted for the content of each LI
element is the width of the parent element's (UL) content less the
margins, padding, and border of the LI elements. The width of the UL
element is determined by the width of its parent, not shown explicitly
here.
<li>The height of each LI element's contents is determined by the
height of the content. The height of the UL element's content is
determined by the sum of the heights of the LI elements' content, plus
LI margins, padding, and borders (see the section on <a
href="flowobj2.html#box-height">box height calculations</a> for
details). Note that <a
href="flowobj2.html#collapsing-margins">vertical margins between the
LI boxes collapse.</a>
<li>The initial border style is 'none', and this value must be changed
for a border to be rendered. In the example above, only the second
list-item element changes the border style.
<li>The right side padding of the LI elements has been set to zero
width. The effect is apparent in the second illustration.
<li>The foreground color of the LI elements has been set
to white for legibility against a blue background.
<li>The margins and padding of the LI elements are transparent (due to
the initial value), so the background color of the UL elements
(orange) shines through the transparent LI margins. However, the
(blue) background color (blue) of the LI elements changes the color of
the LI padding and content.
<li>Although padding and margin properties are not inherited, the LI
elements are still offset by the UL margin.
</ul>
<H2><a name="flow-model">Establishing box positions</a></H2>
<P>The <span class="index-def" title="visual rendering
model"><em>visual rendering model</em></span> describes how user
agents generate a tree of box rendering
objects. The bulk of this model involves calculating the positions
of boxes based on their dimensions, their position in the rendering
tree, and the dimensions of the canvas.
<P>The value of the <span class="propinst-position">'position'</span>
property determines which of the positioning models will determine
a box's final position on the canvas.
<!-- #include src=properties/position.srb -->
<P>The values of this property have the following meanings:
<ul>
<li>'static': Static boxes belong to the normal flow and are described
in this section.
<li>'relative': The box generated for this element will first be
positioned according to the normal flow, then offset. Relative
positioning is described in a <a href="#relative-positioning">separate
section</A>.
<li>'absolute': The box generated for this element will be given an
absolute position (and possibly size) with respect to a positioning
block. Absolutely positioned elements are described in a <a
href="#absolute-positioning">separate section</A>.
<li>'fixed; Fixed positioning is a variant of absolute positioning
where elements are fixed with respect to the canvas. These are
described in the section on <a href="#fixed-positioning">fixed
positioning</A>.
</ul>
<div class="note"><P>
<em><strong>Note.</strong>
The 'static' value causes some user agents to
ignore 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="containing-block">Containing blocks</a></H3>
<P>In CSS2, all box positions are calculated with respect to a
rectangular box called a <span class="index-def" title="containing
block"> <em>containing block</em></span>
<P>The containing block is defined as follows:
<ul>
<li> If a box has no parent, then it has no containing block
<li> Otherwise, if the value of the
<span class="propinst-display">'display'</span> property for the
parent box is anything else besides 'inline' then the containing block
is that parent
<li> Otherwise, the containing block is the containing block
of the parent.
</ul>
<P>For example, for an inline element like EM, the containing block is
typically the enclosing paragraph (P). On the other hand, the
containing block of a positioned element is the element relative to
which it is positioned.
<h3>Direction of flow</h3>
<!-- #include src=properties/direction.srb -->
<P>This property determines the whether inline boxes are laid out
left-to-right or right-to-left and how children of block-level boxes
flow. It may take the following values:
<dl>
<dt><strong>ltr</strong>
<dd>Left to right flow. This is the default value.
<dt><strong>rtl</strong>
<dd> Right to left flow.
<dt><strong>ltr-override</strong>
<dd>[Ian: What does this mean?]
<dt><strong>rtl-override</strong>
<dd>[Ian: What does this mean?]
</dl>
<P>[Ian: Examples here.]
<P>This property also specifies the direction of <a href="./tables.html">
table layout</a>.
<H2><a name="normal-flow">Normal flow</a></H2>
<H3><a name="block-level">Block-level layout</a></H3>
<P><span class="index-def" title="Block-level
layout">Block-level</span> boxes are laid out one after the other,
vertically.
<P>The vertical distance between the top of a box and its preceding
sibling (or parent if no preceding sibling exists) is determined
by the <span class="propinst-margin">'margin'</span> properties.
<P>Vertical margins between adjacent block-level boxes collapses, as
described in the section on <a
href="./flowobj2.html#collapsing-margins">collapsing margins</a>.
<P>For left-to-right flowing content, a block-level box flows inside
the left side of its parent, at a horizontal distance specified by the
<span class="propinst-margin">'margin'</span> properties. For
right-to-left flowing content, boxes flow inside the right side of
their parent.
<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>.
<H4><A NAME="list-item-elements">List-item elements</A></H4>
<!-- INSERT FROSTING LIST STUFF HERE -->
<P>Some block elements generate boxes that may be formatted as
lists. In terms of flow, lists are formatted as other block-level
elements.
<P>For information about lists and examples of list formatting, please
consult the section on <a href="lists.html">lists</a>.
<H3><a name="inline">Inline layout</a></H3>
<P><span class="index-def" title="Inline layout">Inline boxes</span>
are laid out one after the other, horizontally, within a horizontal
space defined by the containing block (see the section on
<a href="flowobj2.html#box-width">box width calculations</a> for more
information).
<P>For left-to-right flow, the horizontal distance between the left
side of a box and its preceding sibling's right side (or parent's
right side if no preceding sibling exists) is determined by the <span
class="propinst-margin">'margin'</span> properties. For right-to-left
flow, the horizontal distance is between the right side of a box and
its preceding sibling's left side (or parent's left side if no
preceding sibling exists).
<P>Horizontally adjacent inline boxes form a
<span class="index-def" title="line box"><em>line box</em>.</span> To
form a paragraph, line boxes are stacked vertically. Note that in the
same block, stacked line boxes have the same width but may vary in
height.
<P>When an inline box is less wide than the width of the line box that
contains it, its horizontal alignment within the line box is
determined by the <span
class="propinst-text-align">'text-align'</span> property.
<P>When an inline box is wider than a line box, it it may be split
into several inline boxes and these boxes distributed across several
lines.
<P>Inline boxes in the same line may have different heights (e.g., an
inline image surrounded by text), so the final height of each line box
is determined by the rules given in the section on <a
href="flowobj2.html#line-height">line height calculations</a>. When
an inline box's height is less than the line box height, the vertical
alignment of the inline box within the line box is determined by the
<span class="propinst-vertical-align">'vertical-align'</span>
property.
<h4><a name="anonymous">Anonymous text boxes</a></h4>
<P>When a block-level element contains text that is not the content of
an inline element, the element generates one or more "anonymous"
inline boxes in the tree of boxes, each of which contains a chunk of
this text.
<div class="example"><P>
For example, the following paragraph (created by the HTML block-level
element P) contains chunks of text separated by
the inline elements EM and STRONG:
<PRE>
<P>Several <EM>emphasized words</EM> appear
<STRONG>in this</STRONG> sentence, dear.</P>
</PRE>
<P>In terms of the document tree, P has five children elements
that contain the following pieces of text:
<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 generates an inline box
for each child and lays all five of them out into successive line
boxes. The width of the P element 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 inline boxes do not fit within a single line box, they will
be split up and distributed across several lines. 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 this last example, the EM inline box has been split into
two EM boxes (call them "split1" and "split2"). If a inline box split
this way has margins, borders, padding, or text decorations, these
have no visible effect after split1 or before split2 (e.g., the border
is not drawn and the margin and padding are not included after
split1).
<div class="example"><P>
Consider the following example:
<PRE>
<STYLE>
EM { padding: 2px ;
margin: 1em ;
border-width: medium;
border-style: dashed;
line-height: 2.4em;
}
</STYLE>
<BODY>
<P>Several <EM>emphasized words</EM> appear here.</P>
</BODY>
</PRE>
<P>Depending on the width of the P, the boxes may be distributed as
follows:</P>
<img src="./images/inline-layout.gif"
alt="Image illustrating the effect of line breaking on the display of margins, borders, and padding.">
<ul>
<li> The margin is inserted before "emphasized" and after "words".
Recall that margins above and below inline elements have no effect.
<li> The padding is inserted before, above, and below
"emphasized" and after, above, and below "words" (i.e.,
neither after "emphasized" nor before "words"). A
dashed border surrounds the padding.
</ul>
</div>
<P>Note that with a small line height, the padding and borders
around text in different lines may overlap.
<h3>Dual-mode elements: run-in and compact</h3>
<p>There are two types of boxes that are inline or block depending on
the context. A <span class="index-def" title="compact box"><em>compact
box</em></span> is one that is put in the margin of the following
block if there is enough room, otherwise, it will be rendered as a
block. A <span class="index-def" title="run-in box"><em>run-in
box</em></span> is one that is rendered inline in the following block,
or as a block if there is no following block. The <span
class="propinst-display">'display'</span> property determines whether
a box is 'compact' or 'run-in'.
<div class=example>
<p>The following example illustrates a compact box.
This document:
<pre>
<style>
DT {display: compact}
DD {margin-left: 4em}
</style>
<dl>
<dt>Short
<dd><p>Description goes here.
<dt>too long for the margin
<dd><p>Description goes here.
</dl>
</pre>
<p>may be rendered as:
<pre>
<b>short</b> Description goes here
<b>too long for the margin</b>
Description goes here
</pre>
</div>
<div class=example>
<p>A 'run-in' element, on the other hand, is useful for run-in
headers, as in this example:
<pre>
<style>
H3 {display: run-in}
H3:after {content: ". "}
</style>
<h3>A run-in heading</h3>
<p>And a paragraph of text that
follows it.
</pre>
<p>which may be rendered as follows:
<pre>
<b>A run-in heading. </b>And a
paragraph of text that
follows it.
</pre>
</div>
<p>A 'run-in' element is rendered exactly like a 'block' element if
the following sibling element is not of type 'block' or is floating or
positioned absolutely. Otherwise the run-in element is rendered inline
as if it were the first inline box of the following block.
<p>Properties apply to a run-in element depending on whether it is
rendered inline or as a block. For example, the <span
class="propinst-white-space">'white-space'</span> property only applies
if the element is rendered as a block.
<p>For a 'compact' element to be rendered as an inline box, it must be
followed by a 'block' element that doesn't float and is not positioned
absolutely. That block must have a <span
class="propinst-margin-left">'margin-left'</span> (or <span
class="propinst-margin-right">'margin-right'</span>
if it's <span class="propinst-direction">'direction'</span> is 'rtl')
that is wide enough for the compact element. That means: the compact
element, when rendered as an inline box, must be a single box (no line
breaks) with overall width (including margins, border and padding) that
is no larger than the margin of the block.
<p>The compact box is outside (to the left or right) of the first line
box of the block, but it takes part in the calculation of that line
box's height. The <span
class="propinst-vertical-align">'vertical-align'</span> property of
the compact box determines its vertical position relative to that line
box.
<p>The horizontal position is always in the margin of the block, as
far to the outside as possible. The compact box's left margin (or
right, if the block's 'direction' is 'rtl') determines the position.
<H3><a name="relative-positioning">Relative positioning</a></H3>
<P>Once a block-level or inline box has been assigned its position
according to the flow model, it may be shifted relative to this
position. This is called <span class="index-def" title="relative
positioning"><em>relative positioning</em></span> and the offset is
specified by the the <span class="propinst-top">'top'</span>, <span
class="propinst-bottom">'bottom'</span>, <span
class="propinst-left">'left'</span>, and <span
class="propinst-right">'right'</span> properties. Offsetting a box in
this way has no effect on sibling boxes; they are not "reflowed" as a
result of the offset. This implies that relative positioning may cause
boxes to overlap.
<P>Relatively positioned elements establish a new reference box
that child elements can be positioned with respect to. See the section
on <a href="#absolute-positioning">absolutely positioned elements</A>
for more on this.
<p>Relatively positioned elements keep their natural shape, including
line breaks and the space originally reserved for them.
Dynamic movement of relatively positioned elements can provide
animation effects in scripting environments (see the section on <a
href="./flowobj2.html#dynamic-positioning">dynamic positioning</a> for
details).</p>
<P>Elements are positioned relatively by setting the <span
class="propinst-position">'position'</span> property to 'relative'.
<p>Relative positioning could also be used as a general form of
superscripting and subscripting except that line height is not
automatically adjusted to take the positioning into consideration. See
the description of <a href="flowobj2.html#line-height">line height
calculations</a> for more information.
<P>Examples of relative positioning are provided in the section <a
href="#comparison">comparing normal, relative, floating, and
absolute positioning</a>.
<H3>Controlling layout behavior: the <span
class="propinst-display">'display'</span> property</H3>
<P>An element of the document language is not inherently inline or block-level (except, perhaps in the minds of the language's designers). CSS
does not assume any default layout behavior for elements. The layout
behavior of every element is determined by the value of its <span
class="propinst-display">'display'</span> property.
<!-- #include src=properties/display.srb -->
<P> An element with a <span class="propinst-display">'display'</span>
value of 'block' causes the generation of a <a
href="#block-level">block-level</a> box.
<P>A value of 'list-item' is similar to 'block' except that a
list-item marker is added. For example, in HTML, LI will typically
have this value.
<P> An element with a <span class="propinst-display">'display'</span>
value of 'inline' generates an <a href="#inline">inline box</a>. The
box is dimensioned according to the formatted size of the content. If
the content is text, it may span several lines, and there will be a
box on each line. The <a href="flowobj2.html#margin-properties">margin</a>, <a
href="flowobj2.html#border-properties">border</a>, and <a
href="flowobj2.html#padding-properties">padding</a> properties apply to 'inline'
elements, but will not have any effect at the line breaks.
<P> The values 'table', 'row-group', 'column-group', 'row', 'column',
'cell' and 'caption' create tables. See <a
href="tables.html#table-elements">Table elements</a>
<P> A value of 'none' turns off the display of the element (including
any border around the element); 'none' completely removes the element
so that it does not affect layout at all. Descendent elements will
also be turned off and cannot override this by setting the <span
class="propinst-display">'display'</span> property themselves.
<div class="example"><P>
<PRE>
P { display: block }
EM { display: inline }
LI { display: list-item }
IMG { display: none }
</PRE>
<P> The last rule turns off the display of images.
</div>
<P>[Add pointers to run-in and compact -IJ]
<P> The initial value of <span
class="propinst-display">'display'</span> is 'block', but a user agent
will typically have default values for all document language elements.
<P>UAs may ignore <span class="propinst-display">'display'</span> and use
only the UA's default values. See the section on <a
href="convent.html#conformance">conformance</a> for details.
<P> For many document languages, and in particular for HTML, user agents
may provide a default style sheet that implements the layout behavior
expected of the language's elements. Please consult the <a
href="sample.html">sample style sheet</a> in the appendix for
information about the default layout behavior of HTML 4.0.
<H2><a name="floats">Floats</a>: <span
class="propinst-float">'float'</span> and <span
class="propinst-clear">'clear'</span></H2>
<P>At times, authors may want to control the positioning of a box in a
way that cannot be done within the normal flow. There are three ways to
place a box outside the normal flow:
<ul>
<li>Create a <a href="#floats">floating box</a> that floats
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>Use <a href="#absolute-positioning">absolute positioning</a>.
<li>Set the value of the <span
class="propinst-display">'display'</span> property to 'none' (in which
case, the element does not generate a box at all).
</ul>
<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
their absolutely positioned sister did not exist at all. Later
siblings of floating objects flow with respect to the final
position of the floating element.
<P>Floating and absolutely positioned boxes do affect the flow of
children elements: children elements always flow relative to the
position of their parent (the floater or absolutely positioned
element) unless positioned absolutely themselves.
<P>A floated box is moved to the left or right until the margin,
padding, or border of another block-level element is reached.
<P>User agents take the boundaries of floated boxes into account when
flowing subsequent boxes, i.e., boxes that follow flow around the
floated box. The margins, borders and padding of the floated box are
honored, and the margins never collapse with the margins of adjacent
elements.
<P>To float a box, set the <span class="propinst-float">'float'</span>
property for the element generating the box.
<!-- #include src=properties/float.srb -->
<P> With the value 'none', the generated box will be displayed where
it appears in the text. With a value of 'left' ('right') the element
will be moved to the left ('right') and the text will wrap on the
right (left) side of the element. With a value of 'left' or 'right',
the element is treated as <a href="#block-level">block-level</a> (and
thus the <span class="propinst-display">'display'</span> property is
ignored).
<P> This property is most often used with inline images, but also
applies to text elements.
<div class="example"><P>
The following example will place all IMG elements with
<samp>class="icon"</samp> along the left side of the parent element:
<PRE>
IMG.icon {
float: left;
margin-left: 0;
}
</PRE>
</div>
<div class="example"><P>
The following HTML source:
<PRE>
<STYLE type="text/css">
IMG { float: left }
BODY, P, IMG { margin: 2em }
</STYLE>
<BODY>
<P>
<IMG src=img.gif>
Some sample text that has no other...
</BODY>
</PRE>
<P>could be formatted as:</P>
<img src="./images/floateg.gif"
alt="Image illustrating how floating elements interact with margins.">
<P> Note that the margin of the P element encloses the floating
IMG element.
</div>
<H3>Controlling floats</H3>
<P>The <span
class="propinst-clear">'clear'</span> property specifies whether an
element will allow floating elements on its sides.
<!-- #include src=properties/clear.srb -->
<P>When set for an element E, this property indicates which sides of E
may not be adjacent to sides of a floating element. A value of 'left'
means that E may not be positioned next to any floating elements to
its left; when flowed, E will therefore be moved to the next available
line below. The value 'right' means the same thing, but on the right
side of E.
<P>A value of 'none' means that E may be placed next to
floating objects to the left or right.
<P>A value of 'both' means that E may not be placed next to floating
objects on either side.
<div class="example"><P>
The following style rule means that no H1 element may have a floating
element to its left. All H1 elements will be positioned at the current
left margin.
<PRE>
H1 { clear: left }
</PRE>
</div>
<P>Consult the section on <a
href="flowobj2.html#floating-constraints">floating constraints</a> for
more information about controlling floats.
<H2><a name="absolute-positioning">Absolute positioning</a></H2>
<!--
<P>The position and size are determined by the <span
class="propinst-top">'top'</span>, <span
class="propinst-bottom">'bottom'</span>, <span
class="propinst-left">'left'</span>, and <span
class="propinst-right">'right'</span> properties.
<p>Absolutely positioned elements act like block-level elements, but
since they do not belong to the normal flow, the following properties
do not apply to them: <span class="propinst-float">'float'</span>,
<span class="propinst-clear">'clear'</span>, <span
class="propinst-display">'display'</span> (and therefore <span
class="propinst-list-style-type">'list-style-type'</span>), and all
the <a href="flowobj2.html#margin-properties">margin properties</a>.
-->
<p>Elements that are positioned with respect to a <span
class="index-def" title="reference box"><em>reference
box</em></span> are said to be <span class="index-def"
title="absolute positioning"><em>absolutely positioned</em></span>.
<P>The default <a name="reference-box">reference box</a> is the box
generated for the root element of the <a
href="convent.html#doctree">document tree</a>. However, an element
for which the <span class="propinst-position">'position'</span>
property has been set to a value other than 'static' establishes a new
reference box. Absolutely positioned descendants of the element will
be positioned with regard to the inner edges of the reference box.
Furthermore, an absolutely positioned element establishes a new
context in which normally flowing descendants are aligned.
<P>When the reference box is established by a block-level element, it
has the same width, height, and position as the content and padding
area of the block-level element. When the reference box is established
by an inline element, it has the same width, height, and position as
the content and padding area of the first box generated by the inline
elements. In other words, if the inline element is split into several
boxes on different lines, the reference box is defined by the first
box.
<P>The contents of an absolutely positioned element do not flow around
any other elements. They may or may not obscure the contents of
another element, depending on the <a href="#z-order">z-order</a> of
the overlapping elements.
<P>An absolutely positioned element lives inside of this reference
block, as illustrated below:</p>
<img src="./images/box-coord.gif" alt="Illustration of a reference box">
<H3>Properties to specify position: <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 an <a href="#relative-positioning">relatively</A>,
<a href="#absolute-positioning">absolutely</A> or <a
href="#fixed-positioning">fixed positioned</A> (see below) element is
determined from four properties:
<!-- #include src=properties/top.srb -->
<!-- #include src=properties/right.srb -->
<!-- #include src=properties/bottom.srb -->
<!-- #include src=properties/left.srb -->
<P>Each of these four properties specifies an offset between the
reference box and the element which is being positioned. More
specifically, values indicate the offset between the edge of the
reference box and the corresponding content+padding+border box of the
element that is being positioned.
<P>The values have the following meanings:
<dl>
<dt><strong><span class="value-inst-length"><length></span></strong>
<dd>The offset is a fixed distance from the edge.
<dt><strong><span class="value-inst-percentage"><percentage></span></strong>
<dd>The offset is a percentage of the reference box'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 depends on the width and height specified
for the element.
</dl>
<P>For absolutely positioned elements, the values of the <span
class="propinst-left">'left'</span>, <span
class="propinst-right">'right'</span>, <span
class="propinst-top">'top'</span>, and <span
class="propinst-bottom">'bottom'</span> properties take over the roles
of the corresponding <a href="flowobj2.html#margin-properties">margin
properties</a> (i.e., absolutely positioned element boxes do not have
margins but do have padding and borders).
<P>For more information about the width and height of absolutely
positioned elements, please consult the sections on <a
href="flowobj2.html#box-width">box width calculations</a> and <a
href="flowobj2.html#box-height">box height calculations</a>
respectively.
<H3><a name="fixed-positioning">Fixed positioning</a></H3>
<P>Fixed positioning is a variant of absolute positioning. The only
difference is that absolutely positioned elements are positioned with
respect to a reference box, while fixed positioned elements are
positioned with respect to the canvas. Fixed positioned elements are,
as the name indicates, fixed to the canvas.
<P>For continuous media, fixed boxes do not move when the document is
scrolled. In this respect, they are similar to <a
href="./colors.html#background-properties">fixed background
images</a>.
<P>In a paged medium, fixed positioned elements are repeated on every
page. This is useful for placing, for instance, a signature at the
bottom of each page.
<H2><a name="comparison">Comparison of normal, relative, floating, absolute positioning</a></H2>
<P>To illustrate the relationship between normal flow, relative
positioning, floats, and absolute positioning, we provide a series of
examples in the following sections based on the following HTML
fragment:
<pre>
<BODY>
<P>Beginning of body contents.
<SPAN id=outer> Start of outer contents.
<SPAN id=inner> Inner contents.</SPAN>
End of outer contents.</SPAN>
End of body contents.
</P>
</BODY>
</PRE>
<p>The final positioning of the <em>outer</em> and <em>inner</em>
spans vary in each example. In each illustration, the numbers to
the left of the illustration indicate the normal position of the
double-spaced (for clarity in this example) lines.</p>
<P> </P>
<H3>Normal flow</H3>
<P> </P>
<p>Consider the following CSS declarations for <em>outer</em> and
<em>inner</em> that don't alter the normal flow of elements:</p>
<PRE>
#outer {color: red;}
#inner {color: blue;}
</PRE>
<p>This results in something like the following:</p>
<img src="./images/flow-generic.gif"
alt="Image illustrating the normal flow of text between parent and sibling elements.">
<H3>Relative positioning</H3>
<P>To see the effect of relative positioning, consider the following CSS rules:
<PRE>
BODY {line-height: 200%}
#outer {position: relative; top: -12px; color: red;}
#inner {position: relative; top: 12px; color: blue;}
</PRE>