The visual formatting model does not specify all aspects of
formatting (e.g., it does not specify a letter-spacing algorithm). Conforming user agents may behave
differently for those formatting issues not covered by this
specification.

User agents for continuous media
generally offer users a viewport (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 initial containing block).

When the viewport is smaller than the document'sinitialcontainingblock,areaofthecanvasonwhichthedocumentisrendered, the user agent should offer a scrolling
mechanism.
There is at most
one viewport per canvas, but user
agents may render to more than one canvas (i.e., provide different
views of the same document).

In CSS2,CSS 2.1, many box positions and sizes are calculated with respect
to the edges
of a rectangular box called a containing block. In
general, generated boxes act as containing blocks for descendant
boxes; we say that a box "establishes" the containing block for its
descendants. The phrase "a box's containing block" means "the
containing block in which the box lives," not the one it generates.

Each box is given a position with respect to its containing block,
but it is not confined by this containing block; it may overflow.

Ifthispropertyhasthevalue'auto',thecontainingblockheightwillgrowtoaccommodatethedocument'scontent.Theinitialcontainingblockcannotbepositionedorfloated(i.e.,useragentsignorethe'position'and'float'propertiesfortherootelement).The details of
how a containing block's dimensions are calculated are described in
the next chapter.

The following sections describe the types of boxes that may be
generated in CSS2.CSS 2.1. A box's type affects, in part, its behavior in the
visual formatting model. The 'display' property, described below,
specifies a box's type.

Block-level elements are those elements of
the source document that are formatted visually as
blocks (e.g., paragraphs). Several values of the 'display' property make an element
block-level: 'block', 'list-item', 'compact'and 'run-in' (part of the
time; see compactandrun-in boxes),
and 'table'.

(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 anonymous block box
around "Some text".

[D]Diagram showing the
three boxes, of which one is anonymous, for the example above.

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 only block boxes
inside it, by wrapping any inline boxes in an anonymous block box.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HEAD>
<TITLE>Anonymous text interrupted by a block</TITLE>
</HEAD>
<BODY>
This is anonymous text before the P.
<P>This is the content of P.</>P.</P>This is anonymous text after the P.
</BODY>

The BODY element contains a chunk (C1) of anonymous text followed
by a block-level element followed by another chunk (C2) of anonymous
text. The resulting boxes would be an anonymous block box for BODY,
containing an anonymous block box around C1, the P block box, and
another anonymous block box around C2.

The properties of 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.

Inline-level
elements are those elements of the source document that
do not form new blocks of content; the content is distributed in lines
(e.g., emphasized pieces of text
within a paragraph, inline images,
etc.). Several values of the 'display' property make an element
inline: 'inline', 'inline-table',
'compact'and 'run-in' (part of the time; see compactandrun-in boxes).
Inline-level elements generate inline
boxes.

The P<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),(<em>), but the other boxes ("Some" and "text") are inline boxes generated by a block-level element (P).(<p>). The latter are called anonymous inline
boxes, because they don't have an associated inline-level element.

Such anonymous inline boxes inherit inheritable properties from
their block parent box. Non-inherited properties have their initial
value. In the example, the color of the anonymous initialinline boxes is
inherited from the P, but the background is transparent.

If a block
box (that does not float and is not
absolutely positioned) follows the compactrun-in
box, the compactrun-in box isformattedlikeaone-lineinlinebox.becomes the resultingfirstinline box widthiscomparedtooneofthesidemarginsoftheblockbox.Thechoiceof leftorrightmarginisdeterminedbythe'direction'specifiedfortheelementproducingthe containingblock forthecompactboxandfollowingbox.

Arun-inheading.Andaparagraph of thecompactboxdeterminestheverticalpositionofthecompactboxrelativetothatlinebox.Thehorizontalpositionofthecompactboxisalwaysinthemarginoftheblockbox.Anelementthatcannotbeformattedononelinecannotbeplacedinthemargintextthatfollowsit.

Despiteappearingvisuallypart of the following block.Forexample,a'compact'elementinHTMLthatcontainsaBRelementwillalwaysbeformattedasablock box(assumingthedefaultstyleforBR,whichinsertsanewline).Forplacingmulti-linetextsinthemargin,the'float'propertyisoftenmoreappropriate.Thefollowingexampleillustratesacompactbox.<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0//EN"><HTML><HEAD><TITLE>Acompactboxexample</TITLE><STYLEtype="text/css">DT{display:compact}DD{margin-left:4em}</STYLE></HEAD><BODY><DL><DT>Short<DD><P>Descriptiongoeshere.<DT>toolongforthemargin<DD><P>Descriptiongoeshere.</DL></BODY></HTML>Thisexamplemightbeformattedas:shortDescriptiongoesheretoolongforthemarginDescriptiongoeshereThe'text-align'propertycanbeusedtoalignthecompactelementinsidethemargin:againsttheleftedgeofthemargin('left'),againsttherightedge('right'),orcenteredinthemargin('center').Thevalue'justify'doesn'tapply,andishandledaseither'left'or'right',dependingonthe'direction'oftheblock-levelelementinwhosemarginthecompactelementisformatted.('left'ifthedirectionis'ltr','right'ifitis'rtl'.)Pleaseconsultthesectionongeneratedcontentforinformationabouthowcompactboxesinteractwithgeneratedcontent.9.2.4Run-inboxesArun-inboxbehavesasfollows:Ifablockbox(thatdoesnotfloatandisnotabsolutelypositioned)followstherun-inbox,
therun-inboxbecomesthefirstinlineboxoftheblockbox.Otherwise,therun-inboxbecomesablockbox.A'run-in'boxisusefulforrun-inheaders,asinthisexample:<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0//EN"><HTML><HEAD><TITLE>Arun-inboxexample</TITLE><STYLEtype="text/css">H3{display:run-in}</STYLE></HEAD><BODY><H3>Arun-inheading.</H3><P>Andaparagraphoftextthatfollowsit.</BODY></HTML>Thisexamplemightbeformattedas:a run-in heading.Andaparagraphoftextthatfollowsit.Thepropertiesoftherun-inelement areinheritedstillinheritsproperties from its parent
in the source tree,notfromtheblockboxitvisuallybecomespartof.tree.

Please consult the section on
generated content
for information about how run-in boxes interact with generated
content.

This value causes an element (e.g., LI in HTML) to generate a
principal block box and a list-item inline box. For information about
lists and examples of listformatting,pleaseconsultthesectiononlists.markerThisvaluedeclaresgeneratedcontentbeforeorafteraboxtobeamarker.Thisvalueshouldonlybeusedwith:beforeand:afterpseudo-elementsattachedtoblock-levelelements.Inothercases,thisvalueisinterpretedas'inline'.listformatting, please consult the section on
markersformoreinformation.lists.

none

This
value causes an element to generate no boxes in the formatting structure (i.e.,
the element has no effect on layout). Descendant elements do not
generate any boxes either; this behavior cannot be
overridden by setting the 'display' property on the descendants.

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 formatting structure that affect
formatting but are not visible themselves. Please consult the section
on visibility for details.

Floats. In the float model,
a box is first laid out according to the normal flow, then
taken out of the flow and shifted
to the left or right as far as possible. Content may
flow along the side of a float.

Absolute positioning.
In the absolute positioning model, a box is removed from
the normal flow entirely (it has no impact on later siblings)
and assigned a position with respect to a containing block.

Note.CSS2'sCSS 2.1's positioning schemes help authors make their documents
more accessible by allowing them to avoid mark-up tricks
(e.g., invisible images) used for layout effects.

The box's position is calculated according to the normal flow (this is called the position in
normal flow). Then the box is offset relative to its normal position. When
a box B is relatively positioned, the position of the following box is
calculated as though B were not offset.

The box's position is calculated according to the 'absolute'
model, but in addition, the box is fixed with respect to some reference.
Aswiththe'absolute'model,thebox'smarginsdonotcollapsewithanyothermargins.
In the case of continuoushandheld,projection,screen,tty,andtv media ,types,
the box is fixed with respect to the viewport(andand doesn't move when
scrolled).scrolled. In the case of pagedtheprint media ,type, the box is fixed with
respect to the page, even if that page is seen through a viewport
(in the case of a print-preview, for example). Forothermediatypes,thepresentationisundefined.
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 viewport on the screen, but
not at the top of each printed page. The two specifications may be
separated by using an @media
rule, as in:

This property specifies how far aanabsolutelypositioned box's top
contentmargin edge is offset below the top edge of the box's containing block. Forrelativelypositionedboxes,theoffsetiswithrespecttothetopedgesoftheboxitself(i.e.,theboxisgivenapositioninthenormalflow,thenoffsetfromthatpositionaccordingtotheseproperties).Note:Forabsolutelypositionedelementswhosecontainingblockisbasedonablock-levelelement,thispropertyisanoffsetfromthepaddingedgeofthatelement.

Like'top',but specifies how far a box's right contentmargin edge is
offset to the left of the right edge of the box's containing block. Forrelativelypositionedboxes,theoffsetiswithrespecttotherightedgeoftheboxitself.Note:Forabsolutelypositionedelementswhosecontainingblockisbasedonablock-levelelement,thispropertyisanoffsetfromthepaddingedgeofthatelement.

Like'top',but specifies how far a box's left contentmargin edge is
offset to the right of the left edge of the box's containing block. Forrelativelypositionedboxes,theoffsetiswithrespecttotheleftedgeoftheboxitself.Note:Forabsolutelypositionedelementswhosecontainingblockisbasedonablock-levelelement,thispropertyisanoffsetfromthepaddingedgeofthatelement.

The offset is a percentage of the containing block's box width (for 'left' or 'right') or height (for 'top' and 'bottom'). For 'top'
and 'bottom', if the height of the
containing block is not specified explicitly
(i.e., it depends on content height), the percentage value
is interpreted like 'auto'. Negativevaluesareallowed.

auto

The effect of this value
depends on which of related properties have the value 'auto' as
well. See the sections on the
width
and height
of absolutely positioned,
non-replaced elements for details.

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 'margin' properties. Vertical margins
between adjacent block boxes in a block formatting context collapse.

In a block formatting context, each box's left outer edge touches
the left edge of the containing block (for right-to-left formatting,
right edges touch). This is true even in the presence of floats
(although a box's contentarealineboxes may shrink due to the floats).

For information about page breaks in paged media, please consult
the section on allowed
page breaks.

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. The boxes 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 line box.

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 'vertical-align' property.
When several inline boxes cannot fit horizontally 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.

In general, the left edge of a line box touches the left edge
of its containing block and the right edge touches the right edge of
its containing block. However, floating boxes may come between the
containing block edge and the line box edge. Thus, although line
boxes in the same inline formatting context generally have the same
width (that of the containing block), they may vary in width if
available horizontal space is reduced due to floats. Line boxes in the same inline formatting
context generally vary in height (e.g., one line might contain a tall
image while the others contain only text).

When the total width of the inline boxes on a line is less than the
width of the line box containing them, their horizontal distribution
within the line box is determined by the 'text-align' property. If that
property has the value 'justify', the user agent may stretch the
inline boxes as well.

SinceWhen an inline box maynotexceedexceeds the width of a line box, longinlineboxesareitis split into several boxes and these boxes are distributed across several line boxes. Ifaninlineboxcannotbesplit(e.g.iftheinlineboxcontainsasinglecharacter,orlanguagespecificwordbreakingrulesdisallowabreakwithintheinlinebox,oriftheinlineboxisaffectedbyawhite-spacevalueofnowraporpre),thentheinlineboxoverflowsthelinebox.

When an inline box is split, margins,
borders, and padding have no visual effect where the split occurs.Formattingofmargins,borders,andpaddingmaynotbefullydefinedifthesplitoccurs withinabidirectionalembedding.(oratanysplit,whenthereareseveral).

The P element generates a block box that contains five inline
boxes, three of which are anonymous:

Anonymous: "Several"

EM: "emphasized words"

Anonymous: "appear"

STRONG: "in this"

Anonymous: "sentence, dear."

To format the paragraph, the user agent flows the five boxes into
line boxes. In this example, the box generated for the P element
establishes the containing block for the line boxes. If the containing
block is sufficiently wide, all the inline boxes will fit into a
single line box:

Several emphasized words appear in this sentence, dear.

If not, the inline boxes will be split up and distributed across
several line boxes. The previous paragraph might be split as follows:

Several emphasized words appear
in this sentence, dear.

or like this:

Several emphasizedwords appear in this
sentence, dear.

In the previous example, the EM box was split into two EM boxes
(call them "split1" and "split2"). Margins, borders,
padding, or text decorations have no visible effect after split1 or
before split2.

Once a box has been laid out according to the normal flow,orfloated, it may be shifted relative to
this position. This is calledrelativepositioning.Offsettingabox(B1)inthiswayhasnoeffectoncalledrelativepositioning.Offsettingabox(B1)inthiswayhasnoeffectonthebox(B2)thatfollows:B2isgivenapositionasifB1werenotoffsetandB2isnotre-positionedafterB1'soffsetisapplied.Thisimpliesthatrelativepositioningmaycauseboxestooverlap.

If'right'isspecifiedas'auto',itscomputedvalueisminus the
box(B2)thatfollows:B2valueof'left'.

Ifneither'left'nor'right' is givena'auto',the position asisover-constrained,andoneofthemhastobeignored. If B1werenotoffsetthe'direction'propertyis'ltr',thevalueof'left'wins and B2'right'becomes-'left'.If'direction' is notre-positionedafterB1'soffset'rtl','right'winsand'left' is
applied.Thisimpliesthatrelativepositioningmaycauseboxestooverlap.ignored.

The'top'and'bottom'propertiesmove relatively positioned
boxeskeepelement(s)upordownwithoutchanging their normalflowsize,includinglinebreaksandsize.'top'moves the
spaceoriginallyreservedforthem.Arelativelypositionedboxestablishesanewanewcontainingblockfornormalflowchildrenboxesdown, and positioneddescendants.'bottom'movesthemup.Sinceboxesarenotsplitorstretchedas a relativelypositionedboxisgeneratedwhenresultof'top'or'bottom', the
'position'propertyforanelementhascomputedvaluesarealways:top=-bottom.Ifbothare'auto',theircomputedvaluesareboth'0'.Ifoneofthemis'auto',itbecomes the value'relative'.negativeof the offsetother.Ifneither is specifiedby'auto','bottom'isignored(i.e., the 'top',computedvalueof 'bottom' ,'left',and'right'properties.willbeminusthevalueof'top').

Dynamic movement of relatively positioned boxes can produce
animation effects in scripting environments (see also the 'visibility' property). Relative
positioning may 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 line height calculations for more
information.

A float is a box that is shifted to the left or right on the
current line. The most interesting characteristic of a float (or
"floated" or "floating" box) is that content may flow along its side
(or be prohibited from doing so by the 'clear' property). Content flows down
the right side of a left-floated box and down the left side of a
right-floated box. The following is an introduction to float
positioning and content flow;theexactrulesgoverningfloatbehavioraregiveninthedescriptionofthe'float'property.Afloatedboxmusthaveanexplicitwidth(assignedviathe'width'property,oritsintrinsicwidthflow;theexactrulesgoverningfloatbehavioraregiven in
the casedescription of replacedelements).Anyfloatedboxbecomesthe'float'property.

A blockfloated box thatis
shifted to the left or right until its outer edge touches the
containing block edge or the outer edge of another float. The top of
the floated box is aligned with the top of the current line box (or
bottom of the preceding block box if no line box exists).

If there isn't enough horizontal room onthecurrentlinefor the
float, it is shifted downward,linebyline,downward until alinehasroomforit.eitheritfitsortherearenomorefloatspresent.

Since a float is not in the flow, non-positioned block boxes
created before and after the float box flow vertically as if the float
didn't exist. However, line boxes created next to the float are
shortened to make room for the floated box. Ifashortenedlineboxistoosmalltocontainanyfurthercontent,thenitisshifteddownwarduntileitheritfitsortherearenomorefloatspresent.
Any content in the current line before a floated box is reflowed
in the first available line on the other side of the float.
Inotherwords,ifinlineboxesareplacedonthelinebeforealeftfloatisencounteredthatfitsintheremaininglineboxspace,theleftfloatisplacedonthatline,alignedwiththetopofthelinebox,andthentheinlineboxesalreadyonthelinearemovedaccordinglytotherightofthefloat(therightbeingtheothersideoftheleftfloat)andviceversaforrtlandrightfloats.

The IMG box is floated to the left. The content that follows is
formatted to the right of the float, starting on the same line as the
float. The line boxes to the right of the float are shortened due to
the float's presence, but resume their "normal" width (that of the
containing block established by the P element) after the float. This
document might be formatted as:

[D]Formatting would have been exactly the same if the document had
been:

because the content to the left of the float is displaced by
the float and reflowed down its right side.

Asstatedinsection8.3.1,
the margins of floating boxes never collapse with margins of
adjacent boxes. Thus, in the previous example, vertical margins do not
collapse between the P box
and the floated IMG box.

Thecontentsoffloatsarestackedasiffloatsgeneratednewstackingcontexts,exceptthatanyelementsthatactuallycreatenewstackingcontextstakepartinthefloat'sparent'sstackingcontext.
A float can overlap other boxes in the normal flow (e.g., when a
normal flow box next to a float has negative margins). When aninlineboxoverlapswithafloat,thecontent,background,andbordersoftheinlineboxthishappens,floats are rendered in front of thefloat.Whenablockboxoverlaps,thebackgroundandbordersoftheblockboxarerenderednon-positionedin-flowblocks,but behind thefloatandareonlybevisiblewheretheboxistransparent.Thecontentoftheblockboxisrenderedinfrontofthefloat.in-flowinlines.

Example(s):

Here is another illustration, showing what happens when a float
overlaps borders of elements in the normal flow.

[D]A floating image obscures borders
of block boxes it overlaps.

The following example illustrates the use of the 'clear' property to prevent content
from flowing next to a float.

Example(s):

Assuming a rule such as this:

p { clear: left }

formatting might look like this:

[D]Both paragraphs have set 'clear: left', which
causes the second paragraph to be "pushed down" to a position below
the float --— its top margin expands to accomplish this (see the 'clear' property).

This property specifies whether a box should float to the left,
right, or not at all. It may be set for elements that generate boxes
that are not
absolutely positioned.
The values of this property have
the following meanings:

left

The element generates a block box that is
floated to the left. Content flows on the right side of the box,
starting at the top (subject to the 'clear' property).

The'display'isignored,unlessithasthevalue'none'.right

Same as 'left', but content flows on the left side of the box,
starting at the top.

The left outer edge of a
left-floating box may not be to the left of the left edge of its containing block. An
analogous rule holds for right-floating elements.

If the current box is left-floating, and there are any leftfloatingleft-floating
boxes generated by elements earlier in the source document,
then for each such earlier box, either the left outer edge of the current box must be
to the right of the right outer edge
of the earlier box, or its top must be lower than the bottom of the
earlier box. Analogous rules hold for right-floating boxes.

The right outer edge of a
left-floating box may not be to the right of the left outer edge of any right-floating
box that is to the right of it. Analogous rules hold for
right-floating elements.

The outer top of a floating box
may not be higher than the outer top of any block or floated box generated by an element
earlier in the source document.

The outer top of an element's
floating box may not be higher than the top of any line-box containing a box
generated by an element earlier in the source document.

A left-floating box that has another left-floating box to its left
may not have its right outer edge to the right of its containing
block's right edge. (Loosely: a left float may not stick out at the
right edge, unless it is already as far to the left as possible.) An
analogous rule holds for right-floating elements.

A floating box must be placed as high as possible.

A left-floating box must be put as far to the left as
possible, a right-floating box as far to the right as possible. A
higher position is preferred over one that is further to the
left/right.

This property indicates which sides of an element's box(es) may
not be adjacent to an earlier floating box. (Itmaybethattheelementitselfhasfloatingdescendants;The 'clear' property hasnoeffectonthose.)Thispropertymayonlybespecifiedforblock-levelelements(includingfloats).doesnotconsiderfloatsinsidetheelementitselforinotherblockformattingcontexts.

For
compactandrun-in boxes,
this property applies to the final block box to which the compactorrun-in box belongs.

Values have the following meanings when applied to non-floating
block boxes:

left

The topmarginclearance of the generated box isincreasedenoughthatissettotheamountnecessarytoplace the
top border edge is below the bottom outer edge of any left-floating
boxes that resulted from elements earlier in the source document.

right

The topmarginclearance of the generated box is increasedenoughthatsettotheamountnecessarytoplace the
top border edge is below the bottom outer edge of any right-floating
boxes that resulted from elements earlier in the source document.

both

The clearanceofthe generated box is movedsettotheamountnecessarytoplacethetopborderedgeis below allfloatingboxesthebottomouteredge of earlieranyright-floatingandleft-floatingboxesthatresultedfrom elements earlier in the
source document..document.

When the property is set on floating elements, it results in a
modification of the rules for
positioning the float. An extra constraint (#10) is added:

The top outer edge
of the float must be below the bottom outer
edge of all earlier left-floating boxes (in the case of 'clear:
left'), or all earlier right-floating boxes (in the case of 'clear:
right'), or both ('clear: both').

In the absolute positioning model, a box is explicitly offset with
respect to its containing block. It is removed from the normal flow
entirely (it has no impact on later siblings). An absolutely
positioned box establishes a new containing block for normal flow
children and absolutely(butnotfixed) positioned descendants. However, the contents of an
absolutely positioned element do not flow around any other boxes. They
may ormaynotobscure the contents of another box,box(orbeobscuredthemselves),
depending on the
stack levels of the overlapping boxes.

Fixed positioning is a subcategory of absolute positioning. The
only difference is that for a fixed positioned box, the containing
block is established by the viewport. For continuous media, fixed
boxes do not move when the document is scrolled. In this respect, they
are similar to fixed
background images. For paged media, boxes
with fixed positions are repeated on every page. This is useful for
placing, for instance, a signature at the bottom of each page.

Authors may use fixed positioning to create frame-like presentations.
Consider the following frame layout:

[D]This might be achieved with the following HTML document and
style rules:

The final positions of boxes generated by the outer and
inner elements vary in each example. In each illustration,
the numbers to the left of the illustration indicate the normal flow position of the double-spaced (for
clarity) lines.

(Note:Note. The illustrationsusedifferenthorizontaldiagramsinthissectionareillustrative and verticalscales.)nottoscale.TheyaremeanttohighlightthedifferencesbetweenthevariouspositioningschemesinCSS2.1,andarenotintendedtobereferencerenderingsoftheexamplesgiven.

Consider the following CSS declarations for outer and
inner that don't alter the normal
flow of boxes:

#outer { color: red }
#inner { color: blue }

The P element contains all inline content: anonymous inline text and two SPAN
element.elements. Therefore, all of the content will be laid out
in an inline formatting context, within a containing block
established by the P element, producing something like:

Text flows normally up to the outer element. The
outer text is then flowed into its normal flow position and
dimensions at the end of line 1. Then, the inline boxes containing the
text (distributed over three lines) are shifted as a unit by '-12px'
(upwards).

The contents of inner, as a child of outer, would
normally flow immediately after the words "of outer contents" (on line
1.5). However, the inner contents are themselves offset
relative to the outer contents by '12px' (downwards), back to
their original position on line 2.

Note that the content following outer is not affected by the
relative positioning of outer.

[D]Note also that had the offset of outer been '-24px', the
text of outer and the body text would have overlapped.

Text flows normally up to the inner box, which is pulled
out of the flow and floated to the right margin (its 'width' has been assigned explicitly).
Line boxes to the left of the float are shortened, and the
document's remaining text flows into them.

[D]To show the effect of the 'clear' property, we add a sibling
element to the example:

cause the inner box to float to the right as before and the
document's remaining text to flow into the vacated space:

[D]However, if the 'clear'
property on the sibling element is set to 'right' (i.e., the
generated sibling box will not accept a position next to
floating boxes to its right), the sibling content begins to
flow below the float:

which cause the top of the outer box to be positioned with
respect to its containing block. The containing block for a positioned
box is established by the nearest positioned ancestor (or, if none
exists, the initial containing
block, as in our example). The top side of the outer box
is '200px' below the top of the containing block and the left side is
'200px' from the left side. The child box of outer is flowed
normally with respect to its parent.

[D]The following example shows an absolutely positioned box that is a
child of a relatively positioned box. Although the parent
outer box is not actually offset, setting its 'position' property to 'relative'
means that its box may serve as the containing block for positioned
descendants. Since the outer box is an inline box that is
split across several lines, the first inline box's top and left edges
(depicted by thick dashed lines in the illustration below)
serve as references for 'top' and
'left' offsets.

the containing block for inner becomes the initial containing block (in our
example). The following illustration shows where the inner
box would end up in this case.

[D]Relative and absolute positioning may be used to implement change
bars, as shown in the following example. The following document:fragment:

<P style="position: relative; margin-right: 10px; left: 10px;">
I used two red hyphens to serve as a change bar. They
will "float" to the left of the line containing THIS
<SPAN style="position: absolute; top: auto; left: -1em; color: red;">--</SPAN>
word.</P>

might result in something like:

[D]First, the paragraph (whose containing block sides are shown in the
illustration) is flowed normally. Then it is offset '10px' from the
left edge of the containing block (thus, a right margin of '10px' has
been reserved in anticipation of the offset). The two hyphens acting
as change bars are taken out of the flow and positioned at the current
line (due to 'top: auto'), '-1em' from the left edge of its containing
block (established by the PPinitsfinalposition).Theresultisthatthechangebarsseemto"float"totheleftofthecurrentline.

Thestacklevelofthegeneratedbox in itsfinalposition).the resultcurrentstackingcontext is thatthechangebarsseemto"float"tothe leftofsameasitsparent'sbox. The
currentline.9.9Layeredpresentationboxdoesnotestablishanewlocalstackingcontext.

In thefollowingsections,thissection, the expression "in front of"
means closer to the user as the user faces the screen.

In CSS2,CSS 2.1, each box has a position in three dimensions. In addition
to their horizontal and vertical positions, boxes lie along a "z-axis"
and are formatted one on top of the other. Z-axis positions are
particularly relevant when boxes overlap visually. This section
discusses how boxes may be positioned along the z-axis.

Each box belongs to one stacking context. Each box in a given
stacking context has an integer stack level, which
is its position on the z-axis relative to other boxes in the same
stacking context. Boxes with greater stack levels are always formatted
in front of boxes with lower stack levels. Boxes may have negative
stack levels. Boxes with the same stack level in a stacking context
are stacked bottom-to-top according to document tree order.

Each stacking context towhichitbelongs(givenbythe'z-index'property).Anelement'sboxhasthesamestacklevelasitsparent'sboxunlessgivenadifferentstacklevelwiththe'z-index'property.9.9.1Specifyingthestacklevel:the'z-index'property'z-index'Value:auto|<integer>|inheritInitial:autoAppliesto:positionedelementsInherited:noPercentages:N/AMedia:visualForapositionedbox,the'z-index'propertyspecifies:Thestackleveloftheboxinthecurrentstackingcontext.Whethertheboxestablishesalocalstackingcontext.Valueshaveconsistsof the following
meanings:<integer>Thisintegerisstackinglevels(frombacktofront):

the stacklevelbackgroundandborders of the generatedboxinelementforming the currentstacking context.

The contentsofinlineblocksandinlinetablesarestackedasifthey generated boxnewstackingcontexts,exceptthatanyelementsthatactuallycreatenewstackingcontextstakepart in the currentparent
stacking contextisthesameasitsparent'sbox.context.Theyarethenpaintedatomicallyin the boxdoesnotestablishanewlocalinline
stacking context.level.

In the following example, the stack levels of
the boxes (named with their "id" attributes) are:
"text2"=0, "image"=1, "text3"=2, and "text1"=3. The
"text2" stack level is inherited from the root box. The
others are specified with the 'z-index' property.

This example demonstrates the notion of
transparency. The default behavior of a box is to allow boxes
behind it to be visible through transparent areas in its content. In
the example, each box transparently overlays the boxes below it. This
behavior can be overridden by using one of the existing
background properties.

The characters in certain scripts are written from right to
left. In some documents, in particular those written with the Arabic
or Hebrew script, and in some mixed-language contexts, text in a
single (visually displayed) block may appear with mixed
directionality. This phenomenon is called bidirectionality, or
"bidi" for short.

The Unicode standard ([UNICODE], section 3.11) defines a complex
algorithm for determining the proper directionality of text. The
algorithm consists of an implicit part based on character properties,
as well as explicit controls for embeddings and overrides. CSS2CSS 2.1 relies
on this algorithm to achieve proper bidirectional rendering. The 'direction' and 'unicode-bidi' properties allow
authors to specify how the elements and attributes of a document
language map to this algorithm.

If a document contains right-to-left characters, and if the user
agent displays these characters (withappropriateglyphs,notarbitrarysubstitutessuchasaquestionmark,ahexcode,ablackbox,etc.),inright-to-leftorder, the user
agent must apply the bidirectional algorithm.
(UAsthatrenderright-to-leftcharacterssimplybecauseafontonthesystemcontainsthembutdonotsupporttheconceptofright-to-lefttextdirectionareexemptfromthisrequirement.)
This seemingly one-sided requirement reflects the fact
that, although not every Hebrew or Arabic document contains
mixed-directionality text, such documents are much more likely to
contain left-to-right text (e.g., numbers, text from other languages)
than are documents written in left-to-right languages.

Because the directionality of a text depends on the structure and
semantics of the document language, these properties should in most
cases be used only by designers of document type descriptions (DTDs),
or authors of special documents. If a default style sheet specifies
these properties, authors and users should not specify rules to
override them.

This property specifies the base writing direction of blocks and
the direction of embeddings and overrides (see 'unicode-bidi') for the Unicode
bidirectional algorithm. In addition, it specifies the direction of table column layout, the direction of
horizontal overflow, and the
position of an incomplete last line in a block in case of 'text-align:
justify'.

Values for this property have the following meanings:

ltr

Left-to-right direction.

rtl

Right-to-left direction.

For the 'direction'
property to have any effect on inline-level elements, the 'unicode-bidi' property's value
must be 'embed' or 'override'.

Note.
The 'direction' property, when
specified for table column elements, is not inherited by cells in the
column since columns don'texistarenottheancestorsofthecells in the document tree.
Thus, CSS cannot easily capture the "dir" attribute inheritance rules described
in [HTML40], section 11.3.2.1.

The element does not open an additional level of embedding with
respect to the bidirectional algorithm. For inline-level elements,
implicit reordering works across element boundaries.

embed

If the element is inline-level, this value
opens an additional level of embedding with respect to the
bidirectional algorithm. The direction of this embedding level is
given by the 'direction'
property. Inside the element, reordering is done implicitly. This
corresponds to adding a LRE (U+202A; for 'direction: ltr') or RLE
(U+202B; for 'direction: rtl') at the start of the element and a PDF
(U+202C) at the end of the element.

bidi-override

Iftheelementisinline-levelorablock-levelelementthatcontainsonlyFor inline-level elements,elements this creates an override. Forblock-levelelementsthiscreatesanoverrideforinline-leveldescendentsnotwithinanotherblock.
This means that inside the element, reordering is strictly in sequence
according to the 'direction'
property; the implicit part of the bidirectional algorithm is
ignored. This corresponds to adding a LRO (U+202D; for 'direction:
ltr') or RLO (U+202E; for 'direction: rtl') at the start of the
element and a PDF (U+202C) at the end of the element.

The final order of characters in each block-level element is the
same as if the bidi control codes had been added as described above,
markup had been stripped, and the resulting character sequence had
been passed to an implementation of the Unicode bidirectional
algorithm for plain text that produced the same line-breaks as the
styled text. In this process, non-textual entities such as images are
treated as neutral characters, unless their 'unicode-bidi' property has a
value other than 'normal', in which case they are treated as strong
characters in the 'direction'
specified for the element.

Please note that in order to be able to flow inline boxes in a
uniform direction (either entirely left-to-right or entirely
right-to-left), more inline boxes (including anonymous inline boxes)
may have to be created, and some inline boxes may have to be split up
and reordered before flowing.

Because the Unicode algorithm has a limit of
1561 levels of
embedding, care should be taken not to use 'unicode-bidi' with a value other
than 'normal' unless appropriate. In particular, a value of 'inherit'
should be used with extreme caution. However, for elements that are,
in general, intended to be displayed as blocks, a setting of
'unicode-bidi: embed' is preferred to keep the element together in
case display is changed to inline (see example below).

The following example shows an XML document with bidirectional
text. It illustrates an important design principle: DTD designers should take bidi
into account both in the language proper (elements and attributes) and
in any accompanying style sheets. The style sheets should be designed
so that bidi rules are separate from other style rules. The bidi rules
should not be overridden by other style sheets so that the document
language's or DTD's bidi behavior is preserved.

The HEBREW element is a block with a right-to-left base direction,
the ENGLISH element is a block with a left-to-right base
direction. The PARs are blocks that inherit the base direction from
their parents. Thus, the first two PARs are read starting at the top
right, the final three are read starting at the top left. Please note
that HEBREW and ENGLISH are chosen as element names for explicitness
only; in general, element names should convey structure without
reference to language.

The EMPH element is inline-level, and since its value for 'unicode-bidi' is 'normal' (the
initial value), it has no effect on the ordering of the text. The
HE-QUO element, on the other hand, creates an embedding.

The formatting of this text might look like this if the line length
is long:

Because HEBREW18 must be read before english19, it is on the line
above english19. Just breaking the long line from the earlier
formatting would not have worked. Note also that the first syllable
from english19 might have fit on the previous line, but hyphenation of
left-to-right words in a right-to-left context, and vice versa, is
usually suppressed to avoid having to display a hyphen in the middle
of a line.