📄 visuren.html
字号:
then offset from that position according to these properties).<H2>9.4 <a name="normal-flow">Normal flow</a></H2> <P>Boxes in the normal flow belong to a <a name="x41"><span class="index-def"title="formatting context">formatting context</span></a>, which may beblock or inline, but not both simultaneously. <ahref="#block-box">Block</a> boxes participate in a <ahref="#block-formatting">block formatting</a> context. <ahref="#inline-box">Inline boxes</a> participate in an <ahref="#inline-formatting">inline formatting</a> context.<h3>9.4.1 <a name="block-formatting">Block formatting context</a></h3> <P>In a block formatting context, boxes are laid out one after theother, vertically, beginning at the top of a containing block. Thevertical distance between two sibling boxes is determined by the <a href="box.html#propdef-margin" class="noxref"><spanclass="propinst-margin">'margin'</span></a> properties. Vertical marginsbetween adjacent block boxes in a block formatting context <ahref="box.html#collapsing-margins">collapse</a>.<P>In a block formatting context, each box's left outer edge touchesthe 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 <em>content</em> area may shrink due to the floats).<P>For information about page breaks in paged media, please consultthe section on <a href="page.html#allowed-page-breaks">allowedpage breaks</a>.<H3>9.4.2 <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 containingblock. Horizontal margins, borders, and padding are respected betweenthese boxes. The boxes may be aligned vertically in different ways: theirbottoms or tops may be aligned, or the baselines of text within themmay be aligned. The rectangular area that contains the boxes that forma line is called a <span class="index-def" title="line box"><aname="line-box"><dfn>line box</dfn></a></span>. <P>The width of a line box is determined by a <AHREF="#containing-block">containing block</A>. The height of a linebox is determined by the rules given in the section on <ahref="visudet.html#line-height">line height calculations</a>. A linebox 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 abox B is less than the height of the line box containing it, thevertical alignment of B within the line box is determined by the <a href="visudet.html#propdef-vertical-align" class="noxref"><spanclass="propinst-vertical-align">'vertical-align'</span></a> property.<P>When several inline boxes cannot fit horizontally within a singleline box, they are distributed among two or more vertically-stackedline boxes. Thus, a paragraph is a vertical stack of line boxes. Lineboxes are stacked with no vertical separation and they never overlap.<P>In general, the left edge of a line box touches the left edgeof its containing block and the right edge touches the right edge ofits containing block. However, floating boxes may come between thecontaining block edge and the line box edge. Thus, although lineboxes in the same inline formatting context generally have the samewidth (that of the containing block), they may vary in width ifavailable horizontal space is reduced due to <ahref="#floats">floats</a>. Line boxes in the same inline formattingcontext generally vary in height (e.g., one line might contain a tallimage while the others contain only text).<P>When the total width of the inline boxes on a line is less than thewidth of the line box containing them, their horizontal distributionwithin the line box is determined by the <a href="text.html#propdef-text-align" class="noxref"><spanclass="propinst-text-align">'text-align'</span></a> property. If thatproperty has the value 'justify', the user agent may stretch theinline boxes as well.<P>Since an inline box may not exceed the width of a line box, longinline boxes are split into several boxes and these boxes distributedacross several line boxes. When an inline box is split, margins,borders, and padding have no visual effect where the split occurs.Formatting of margins, borders, and padding may not be fully defined ifthe split occurs within a bidirectional embedding.<P>Inline boxes may also be split into several boxes <em>within thesame line box</em> due to <a href="#direction">bidirectional textprocessing</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 textinterspersed 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 inlineboxes, 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 intoline boxes. In this example, the box generated for the P elementestablishes the containing block for the line boxes. If the containingblock is sufficiently wide, all the inline boxes will fit into asingle line box:<PRE> Several <EM>emphasized words</EM> appear <STRONG>in this</STRONG> sentence, dear.</PRE><P>If not, the inline boxes will be split up and distributed acrossseveral line boxes. The previous paragraph might be split as follows:<PRE>Several <EM>emphasized words</EM> appear<STRONG>in this</STRONG> sentence, dear.</PRE>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"). Margins, borders,padding, or text decorations have no visible effect after split1 orbefore split2.<div class="html-example"><P>Consider the following example:<PRE><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><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></HTML></PRE><P>Depending on the width of the P, the boxes may be distributed asfollows:</P><div class="figure"><P><img src="./images/inline-layout.gif" alt="Image illustrating the effect of line breaking on thedisplay of margins, borders, and padding."><SPAN class="dlink"> <A name="img-inline-layout" href="images/longdesc/inline-layout-desc.html" title="Long description for illustration of margin/borderbehavior on split inline box">[D]</A></SPAN></p></div><ul><li> The margin is inserted before "emphasized" and after "words". <li> The padding is inserted before, above, and below"emphasized" and after, above, and below "words". Adashed border is rendered on three sides in each case.</ul></div><H3>9.4.3 <a name="relative-positioning">Relative positioning</a></H3> <P>Once a box has been laid out according to the <ahref="#normal-flow">normal flow</a>, it may be shifted relative tothis position. This is called <a name="x43"><span class="index-def" title="relativepositioning"><dfn>relative positioning</dfn></span></a>. Offsetting a box(B1) in this way has no effect on the box (B2) that follows: B2 isgiven a position as if B1 were not offset and B2 is not re-positionedafter B1's offset is applied. This implies that relative positioningmay cause boxes to overlap.<p>Relatively positioned boxes keep their normal flow size, includingline breaks and the space originally reserved for them. A relativelypositioned box establishes a new a new <ahref="#containing-block">containing block</a> for normalflow children and positioned descendants.<P>A relatively positioned box is generated when the <a href="visuren.html#propdef-position" class="noxref"><spanclass="propinst-position">'position'</span></a> property for an elementhas the value 'relative'. The offset is specified by the <a href="visuren.html#propdef-top" class="noxref"><spanclass="propinst-top">'top'</span></a>, <a href="visuren.html#propdef-bottom" class="noxref"><spanclass="propinst-bottom">'bottom'</span></a>, <a href="visuren.html#propdef-left" class="noxref"><spanclass="propinst-left">'left'</span></a>, and <a href="visuren.html#propdef-right" class="noxref"><spanclass="propinst-right">'right'</span></a> properties.<P>Dynamic movement of relatively positioned boxes can produceanimation effects in scripting environments (see also the <a href="visufx.html#propdef-visibility" class="noxref"><spanclass="propinst-visibility">'visibility'</span></a> property). Relativepositioning may also be used as a general form of superscripting andsubscripting except that line height is not automatically adjusted totake the positioning into consideration. See the description of <ahref="visudet.html#line-height">line height calculations</a> for moreinformation.<P>Examples of relative positioning are provided in the section <ahref="#comparison">comparing normal flow, floats, and absolutepositioning</a>.<H2>9.5 <a name="floats">Floats</a></H2><P>A float is a box that is shifted to the left or right on thecurrent 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 <a href="visuren.html#propdef-clear" class="noxref"><spanclass="propinst-clear">'clear'</span></a> property). Content flows downthe right side of a left-floated box and down the left side of aright-floated box. The following is an introduction to floatpositioning and content flow; the exact <ahref="#float-rules">rules</a> governing float behavior are given inthe description of the <a href="visuren.html#propdef-float" class="noxref"><span class="propinst-float">'float'</span></a>property.<P>A floated box must have an explicit width (assigned via the <a href="visudet.html#propdef-width" class="noxref"><spanclass="propinst-width">'width'</span></a> property, or its <ahref="conform.html#intrinsic">intrinsic</a> width in the case of <ahref="conform.html#replaced-element">replaced elements</a>). Anyfloated box becomes a <a href="#block-box">block box</a> that isshifted to the left or right until its outer edge touches thecontaining block edge or the outer edge of another float. The top ofthe floated box is aligned with the top of the current line box (orbottom of the preceding block box if no line box exists). If thereisn't enough horizontal room on the current line for the float, it isshifted downward, line by line, until a line has room for it.<P>Since a float is not in the flow, non-positioned block boxescreated before and after the float box flow vertically as if the floatdidn't exist. However, line boxes created next to the float areshortened to make room for the floated box. Any content in thecurrent line before a floated box is reflowed in the first availableline on the other side of the float.<P>Several floats may be adjacent, and this model also applies toadjacent floats in the same line.<div class="example"><P style="display:none">Example(s):</P><P>The following rule floats all IMG boxes with<samp>class="icon"</samp> to the left (andsets the left margin to '0'):</p><PRE>IMG.icon { float: left; margin-left: 0;}</PRE></div><div class="html-example"><P>Consider the following HTML source and style sheet:</p><PRE> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><HTML> <HEAD> <TITLE>Float example</TITLE> <STYLE type="text/css"> IMG { float: left }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -