8000 csswg-drafts/css2/box.src at 494ee7ddccc2d998ee29fd42b94022b9e951cb3f · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
836 lines (695 loc) · 32.7 KB

File metadata and controls

836 lines (695 loc) · 32.7 KB
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01//EN'>
<html lang="en">
<!-- $Id: box.src,v 1.89 2012-05-15 14:12:14 bbos Exp $ -->
<HEAD>
<TITLE>Box model</TITLE>
<!--script src="http://www.w3c-test.org/css/harness/annotate.js#CSS21_DEV" type="text/javascript" defer></script-->
</HEAD>
<BODY>
<H1><a name="box-model">Box model</a></H1>
<P>The CSS box model describes the rectangular boxes that are
generated for elements in the <a href="conform.html#doctree">document
tree</a> and laid out according to the <a href="visuren.html">visual formatting
model</a>.
<H2><a name="box-dimensions">Box dimensions</a></H2>
<P>Each box has a
<span class="index-def" title="box::content|content::of a box">
<a name="box-content-area"><dfn>content area</dfn></a></span> (e.g.,
text, an image, etc.) and optional surrounding
<span class="index-def" title="box::padding|padding::of a box">
<a name="box-padding-area"><dfn>padding</dfn></a></span>,
<span class="index-def" title="box::border|border::of a box">
<a name="box-border-area"><dfn>border</dfn></a></span>, and
<span class="index-def" title="box::margin|margin::of a box">
<a name="box-margin-area"><dfn>margin</dfn></a></span> areas; the size
of each area is specified by properties defined below. The following
diagram shows how these areas relate and the terminology used to refer
to pieces of margin, border, and padding:</P>
<div class="figure">
<P><img src="./images/boxdim.png"
alt="Image illustrating the relationship between content, padding, borders, and margins."></P>
</div>
<P>The margin, border, and padding can be broken down into top, right,
bottom, and left segments (e.g., in the diagram, "LM" for left margin,
"RP" for right padding, "TB" for top border, etc.).
<P>The perimeter of each of the four areas (content, padding, border,
and margin) is called an "edge", so each box has four edges:</P>
<dl>
<dt><span class="index-def"
title="content edge"><a name="content-edge"><strong>content edge</strong></a></span>
or <span class="index-def" title="inner edge"><a name="inner-edge"><strong>inner edge</strong></a></span>
<dd>The content edge surrounds the rectangle given by the <a
href="visudet.html#Computing_widths_and_margins">width</a> and <a
href="visudet.html#Computing_heights_and_margins">height</a>
of the box, which often depend on the element's <a
href="conform.html#rendered-content">rendered content</a>.
The four content edges define the
box's <dfn><span class="index-def">content box</span></dfn>.
<dt><span class="index-def" title="padding edge"><a name="padding-edge"><strong>padding edge</strong></a></span>
<dd>The padding edge surrounds the box padding. If the padding
has 0 width, the padding edge is the same as the content edge.
The four padding edges define the
box's <dfn><span class="index-def">padding box</span></dfn>.
<dt><span class="index-def" title="border edge"><a name="border-edge"><strong>border edge</strong></a></span>
<dd>The border edge surrounds the box's border. If the border
has 0 width, the border edge is the same as the padding edge.
The four border edges define the box's <dfn><span class="index-def">border
box</span></dfn>.
<dt><span class="index-def" title="margin edge"><a name="margin-edge"><strong>margin edge</strong></a></span>
or <span class="index-def" title="outer edge"><a name="outer-edge"><strong>outer
edge</strong></a></span>
<dd>The margin edge surrounds the box margin. If the margin
has 0 width, the margin edge is the same as the border edge.
The four margin edges define the box's <dfn><span class="index-def">margin
box</span></dfn>.
</dl>
<P>Each edge may be broken down into a top, right, bottom, and left
edge.
<P>The dimensions of the content area of a box &mdash; the <span
class="index-def" title="box::content width"><a
name="content-width"><dfn>content width</dfn></a></span> and <span
class="index-def" title="box::content height"><a
name="content-height"><dfn>content height</dfn></a></span> &mdash;
depend on several factors: whether the element generating
the box has the <span class="propinst-width">'width'</span>
or <span class="propinst-height">'height'</span> property
set, whether the box contains text or other boxes, whether the
box is a table, etc. Box widths and heights are discussed
in the chapter on <a href="visudet.html">visual formatting
model details</a>.
<P>The background style of the content, padding, and border areas of a
box is specified by the <span
class="propinst-background">'background'</span> property of the
generating element. Margin backgrounds are always transparent.
<H2><a name="mpb-examples">Example of margins, padding, and borders</a></H2>
<P>This example illustrates how margins, padding, and borders
interact. The example HTML document:
<pre class="html-example">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;Examples of margins, padding, and borders&lt;/TITLE&gt;
&lt;STYLE type="text/css"&gt;
UL {
background: yellow;
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: lime;
}
&lt;/STYLE&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
&lt;UL&gt;
&lt;LI&gt;First element of list
&lt;LI class="withborder"&gt;Second element of list is
a bit longer to illustrate wrapping.
&lt;/UL&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
</pre>
<P>results in a <a href="conform.html#doctree">document tree</a> with
(among other relationships) a UL element that has two LI
children.
<P>The first of the following diagrams illustrates what this example
would produce. The second illustrates the relationship between the
margins, padding, and borders of the UL elements and those of its
children LI elements. (Image is not to scale.)</P>
<div class="figure">
<P><img src="./images/boxdimeg.png"
alt="Image illustrating how parent and child margins, borders,
and padding relate."></p>
</div>
<P>Note that:</p>
<ul>
<li>The <a href="#content-width">content width</a> for each LI box is
calculated top-down; the <a href="visuren.html#containing-block">containing
block</a> for each LI box is established by the UL element.
<li>The margin box height of each LI box depends on its <a
href="#content-height">content height</a>, plus top and bottom
padding, borders, and margins. Note that vertical margins between the
LI boxes <a href="#collapsing-margins">collapse.</a>
<li>The right padding of the LI boxes has been set to zero width
(the <span class="propinst-padding">'padding'</span> property). The
effect is apparent in the second illustration.
<li>The margins of the LI boxes are transparent &mdash; margins are always
transparent &mdash; so the background color (yellow) of the UL padding and
content areas shines through them.
<li>The second LI element specifies a dashed border (the
<span class="propinst-border-style">'border-style'</span> property).
</ul>
<H2><a name="margin-properties">Margin properties</a>:
<span class="propinst-margin-top">'margin-top'</span>,
<span class="propinst-margin-right">'margin-right'</span>,
<span class="propinst-margin-bottom">'margin-bottom'</span>,
<span class="propinst-margin-left">'margin-left'</span>, and
<span class="propinst-margin">'margin'</span></H2>
<P>Margin properties specify the width of the <a
href="#box-margin-area">margin area</a> of a box. The <span
class="propinst-margin">'margin'</span> shorthand property sets the
margin for all four sides while the other margin properties only set
their respective side. These properties apply to all elements, but
vertical margins will not have any effect on non-replaced inline
elements.
<P>The properties defined in this section refer to the <span
class="index-def" title="&lt;margin-width&gt;::definition of"><a
name="value-def-margin-width"><strong>&lt;margin-width&gt;</strong></a></span>
value type, which may take one of the following values:</p>
<dl>
<dt><span class="value-inst-length"><strong>&lt;length&gt;</strong></span>
<dd>Specifies a fixed width.
<dt><span class="value-inst-percentage"><strong>&lt;percentage&gt;</strong></span>
<dd>The percentage is calculated
with respect to the <em>width</em> of the generated box's
<a href="visuren.html#containing-block">containing block</a>.
<span class="note">Note that this is true for <span
class="propinst-margin-top">'margin-top'</span> and <span
class="propinst-margin-bottom">'margin-bottom'</span> as well.</span>
If the containing block's width depends on this element, then the
resulting layout is undefined in CSS&nbsp;2.1.
<dt><strong>auto</strong>
<dd>See the section on <a
href="visudet.html#Computing_widths_and_margins">calculating widths and
margins</a> for behavior.
</dl>
<P>Negative values for margin properties are allowed, but there may be
implementation-specific limits.
<!-- #include src=properties/margin-top.srb -->
<p class="note">These properties have no effect on non-replaced inline
elements.</p>
<!-- #include src=properties/margin-right.srb -->
<P>These properties set the top, right, bottom, and left margin of a
box.
<div class="example"><P>
<PRE>
h1 { margin-top: 2em }
</PRE& 7E6C gt;
</div>
<!-- #include src=properties/margin.srb -->
<P> The <span class="propinst-margin">'margin'</span> property is a
shorthand property for setting <span
class="propinst-margin-top">'margin-top'</span>, <span
class="propinst-margin-right">'margin-right'</span>, <span
class="propinst-margin-bottom">'margin-bottom'</span>, and <span
class="propinst-margin-left">'margin-left'</span> at the same place in
the style sheet.
<P> If there is only one component value, it applies to all
sides. If there are two values, the top and bottom margins
are set to the first value and the right and left margins are
set to the second. If there are three values, the top is
set to the first value, the left and right are set to the
second, and the bottom is set to the third. If there are
four values, they apply to the top, right, bottom, and left,
respectively.
<div class="example"><P>
<PRE>
body { margin: 2em } /* all margins set to 2em */
body { margin: 1em 2em } /* top &amp; bottom = 1em, right &amp; left = 2em */
body { margin: 1em 2em 3em } /* top=1em, right=2em, bottom=3em, left=2em */
</PRE>
<P> The last rule of the example above is equivalent to the example
below:
<PRE>
body {
margin-top: 1em;
margin-right: 2em;
margin-bottom: 3em;
margin-left: 2em; /* copied from opposite side (right) */
}
</PRE>
</div>
<H3><a name="collapsing-margins">Collapsing margins</a></H3>
<P>In CSS, the adjoining margins of two or more boxes (which might or
might not be siblings) can combine to form a single margin. Margins
that combine this way are said to <dfn><span
class="index-def">collapse</span></dfn>, and the
resulting combined margin is called a <dfn><span class="index-def"
title="collapsing margin">collapsed margin</span></dfn>.
<P>Adjoining vertical margins collapse, except:
<UL>
<LI>Margins of the root element's box do not collapse.
<LI>If the top and bottom margins of an element with <a
href="visuren.html#clearance">clearance</a> are adjoining, its
margins collapse with the adjoining margins of following siblings
but that resulting margin does not collapse with the bottom margin
of the parent block.
<LI>If the top margin of a box with non-zero computed
'min-height' and 'auto' computed 'height' collapses with the
bottom margin of its last in-flow child, then the child's bottom
margin does not collapse with the parent's bottom margin.
</UL>
<P>Horizontal margins never collapse.
<P ID="what-is-adjoining">Two margins are <span class="index-def"
title="adjoining margins"><DFN>adjoining</DFN></span> if and only if:
<UL>
<LI>both belong to in-flow <a
href="visuren.html#block-boxes">block-level boxes</a> that
participate in the same <a
href="visuren.html#block-formatting">block formatting context</a>
<LI>no line boxes, no clearance, no padding and no border separate
them <span class="note">(Note that <a
href="visuren.html#phantom-line-box">certain zero-height line
boxes</a> (see <a href="visuren.html#inline-formatting">9.4.2</a>)
are ignored for this purpose.)</span>
<LI>both belong to vertically-adjacent box edges, i.e. form one of
the following pairs:
<UL>
<LI>top margin of a box and top margin of its first in-flow child
<LI>bottom margin of box and top margin of its next in-flow
following sibling
<LI>bottom margin of a last in-flow child and bottom margin of its
parent if the parent has 'auto' computed height
<LI>top and bottom margins of a box that does not establish a new
block formatting context and that has zero computed <span
class="propinst-min-height">'min-height'</span>, zero or 'auto'
computed <span class="propinst-height">'height'</span>, and no
in-flow children
</UL>
</UL>
<P>A collapsed margin is considered adjoining to another margin if any
of its component margins is adjoining to that margin.
<P CLASS=note><STRONG>Note.</STRONG> Adjoining margins can be
generated by elements that are not related as siblings or ancestors.
<DIV CLASS=note>
<P><STRONG>Note</STRONG> the above rules imply that:
<UL>
<LI>Margins between a <a href="visuren.html#floats">floated</a> box
and any other box do not collapse (not even between a float and its
in-flow children).
<LI>Margins of elements that establish new block formatting contexts
(such as floats and elements with <span
class="propinst-overflow">'overflow'</span> other than 'visible') do
not collapse with their in-flow children.
<LI>Margins of <a
href="visuren.html#absolutely-positioned">absolutely positioned</a>
boxes do not collapse (not even with their in-flow children).
<LI>Margins of inline-block boxes do not collapse (not even with
their in-flow children).
<LI>The bottom margin of an in-flow block-level element always
collapses with the top margin of its next in-flow block-level
sibling, unless that sibling has clearance.
<LI>The top margin of an in-flow block element collapses with its
first in-flow block-level child's top margin if the element has no
top border, no top padding, and the child has no clearance.
<LI>The bottom margin of an in-flow block box with a 'height' of
'auto' collapses with its last in-flow block-level child's bottom
margin, if:
<UL>
<LI>the box has no bottom padding, and
<LI>the box has no bottom border, and
<LI>the child's bottom margin neither collapses with a top margin
that has clearance, nor (if the box's min-height is non-zero)
with the box's top margin.
</UL>
<LI>A box's own margins collapse if the <span
class="propinst-min-height">'min-height'</span> property is zero,
and it has neither top or bottom borders nor top or bottom padding,
and it has a <span class="propinst-height">'height'</span> of either
0 or 'auto', and it does not contain a line box, and all of its
in-flow children's margins (if any) collapse.
</UL>
</DIV>
<P>When two or more margins collapse, the resulting margin width is
the maximum of the collapsing margins' widths. In the case of negative
margins, the maximum of the absolute values of the negative adjoining
margins is deducted from the maximum of the positive adjoining
margins. If there are no positive margins, the maximum of the
absolute values of the adjoining margins is deducted from zero.
<P ID="collapsed-through">If the top and bottom margins of a box are
adjoining, then it is possible for margins to <DFN><span
class="index-def">collapse through</span></DFN> it. In this case,
the position of the element depends on its relationship with the other
elements whose margins are being collapsed.
<UL>
<LI>If the element's margins are collapsed with its parent's top
margin, the top border edge of the box is defined to be the same as
the parent's.
<LI>Otherwise, either the element's parent is not taking part in the
margin collapsing, or only the parent's bottom margin is
involved. The position of the element's top border edge is the same
as it would have been if the element had a non-zero bottom border.
</UL>
<P>Note that the positions of elements that have been collapsed
through have no effect on the positions of the other elements with
whose margins they are being collapsed; the top border edge position
is only required for laying out descendants of these elements.
<H2><a name="padding-properties">Padding properties</a>:
<span class="propinst-padding-top">'padding-top'</span>,
<span class="propinst-padding-right">'padding-right'</span>,
<span class="propinst-padding-bottom">'padding-bottom'</span>,
<span class="propinst-padding-left">'padding-left'</span>, and
<span class="propinst-padding">'padding'</span>
</H2>
<P>The padding properties specify the width of the <a
href="#box-padding-area">padding area</a> of a box. The <span
class="propinst-padding">'padding'</span> shorthand property sets the
padding for all four sides while the other padding properties only set
their respective side.
<P>The properties defined in this section refer to the <span
class="index-def" title="&lt;padding-width&gt;::definition of"><a
name="value-def-padding-width"><strong>&lt;padding-width&gt;</strong>
</a></span> value type, which may take one of the following values:</p>
<dl>
<dt><span class="value-inst-length"><strong>&lt;length&gt;</strong></span>
<dd>Specifies a fixed width.
<dt><span class="value-inst-percentage"><strong>&lt;percentage&gt;</strong></span>
<dd>The percentage is calculated with
respect to the <em>width</em> of the generated box's <a
href="visuren.html#containing-block">containing block</a>, even for
<span class="propinst-padding-top">'padding-top'</span> and <span
class="propinst-padding-bottom">'padding-bottom'</span>.
If the containing block's width depends on this element, then the
resulting layout is undefined in CSS&nbsp;2.1.
</dl>
<P>Unlike margin properties, values for padding values cannot be
negative. Like margin properties, percentage values for padding
properties refer to the width of the generated box's containing block.
<!-- #include src=properties/padding-top.srb -->
<P>These properties set the top, right, bottom, and left padding of
a box.
<div class="example"><P>
<PRE>
blockquote { padding-top: 0.3em }
</PRE>
</div>
<!-- #include src=properties/padding.srb -->
<P> The <span class="propinst-padding">'padding'</span> property is a
shorthand property for setting <span
class="propinst-padding-top">'padding-top'</span>, <span
class="propinst-padding-right">'padding-right'</span>, <span
class="propinst-padding-bottom">'padding-bottom'</span>, and <span
class="propinst-padding-left">'padding-left'</span> at the same place
in the style sheet.
<P> If there is only one component value, it applies to all
sides. If there are two values, the top and bottom paddings
are set to the first value and the right and left paddings are
set to the second. If there are three values, the top is
set to the first value, the left and right are set to the
second, and the bottom is set to the third. If there are
four values, they apply to the top, right, bottom, and left,
respectively.
<P> The surface color or image of the padding area is specified via
the <span class="propinst-background">'background'</span> property:
<div class="example"><P>
<PRE>
h1 {
background: white;
padding: 1em 2em;
}
</PRE>
<P> The example above specifies a '1em' vertical padding (<span
class="propinst-padding-top">'padding-top'</span> and <span
class="propinst-padding-bottom">'padding-bottom'</span>) and a '2em'
horizontal padding (<span
class="propinst-padding-right">'padding-right'</span> and <span
class="propinst-padding-left">'padding-left'</span>). The 'em' unit is
<a href="syndata.html#absrel-units">relative</a>
to the element's font size: '1em' is equal to the size of the
font in use.
</div>
<H2><a name="border-properties">Border properties</a></H2>
<P>The border properties specify the width, color, and style of the <a
href="#box-border-area">border area</a> of a box. These properties
apply to all elements.
<div class="note"><P>
<em><strong>Note.</strong>
Notably for HTML,
user agents may render borders for certain user interface elements (e.g.,
buttons, menus, etc.) differently than for
"ordinary" elements.
</em>
</div>
<H3><a name="border-width-properties">Border width</A>: <span
class="propinst-border-top-width">'border-top-width'</span>, <span
class="propinst-border-right-width">'border-right-width'</span>, <span
class="propinst-border-bottom-width">'border-bottom-width'</span>,
<span class="propinst-border-left-width">'border-left-width'</span>, and
<span class="propinst-border-width">'border-width'</span></H3>
<P>The border width properties specify the width of the <a
href="#box-border-area">border area</a>. The properties
defined in this section refer to the <span class="index-def"
title="&lt;border-width&gt;::definition of"><a
name="value-def-border-width"
class="value-def"><strong>&lt;border-width&gt;</strong></a></span>
value type, which may take one of the following values:</P>
<dl>
<dt><strong>thin</strong>
<dd>A thin border.
<dt><strong>medium</strong>
<dd>A medium border.
<dt><strong>thick</strong>
<dd>A thick border.
<dt><span class="value-inst-length"><strong>&lt;length&gt;</strong></span>
<dd>The border's thickness has an explicit value. Explicit
border widths cannot be negative.
</dl>
<P>The interpretation of the first three values depends on the user
agent. The following relationships must hold, however:
<P>'thin' &lt;='medium' &lt;= 'thick'.
<P>Furthermore, these widths must be constant throughout a document.
<!-- #include src=properties/border-top-width.srb -->
<P>These properties set the width of the top, right, bottom,
and left border of a box.
<!-- #include src=properties/border-width.srb -->
<P> This property is a shorthand property for setting
<span class="propinst-border-top-width">'border-top-width'</span>,
<span class="propinst-border-right-width">'border-right-width'</span>,
<span class="propinst-border-bottom-width">'border-bottom-width'</span>,
and
<span class="propinst-border-left-width">'border-left-width'</span> at
the same place in the style sheet.
<P> If there is only one component value, it applies to all
sides. If there are two values, the top and bottom borders
are set to the first value and the right and left are
set to the second. If there are three values, the top is
set to the first value, the left and right are set to the
second, and the bottom is set to the third. If there are
four values, they apply to the top, right, bottom, and left,
respectively.
<div class="example"><P>
In the examples below, the comments indicate the resulting widths
of the top, right, bottom, and left borders:
<PRE>
h1 { border-width: thin } /* thin thin thin thin */
h1 { border-width: thin thick } /* thin thick thin thick */
h1 { border-width: thin thick medium } /* thin thick medium thick */
</PRE>
</div>
<H3><A name="border-color-properties">Border color</A>:
<span class="propinst-border-top-color">'border-top-color'</span>,
<span class="propinst-border-right-color">'border-right-color'</span>,
<span class="propinst-border-bottom-color">'border-bottom-color'</span>,
<span class="propinst-border-left-color">'border-left-color'</span>, and
<span class="propinst-border-color">'border-color'</span>
</H3>
<P>The border color properties specify the color of a box's border.
<!-- #include src=properties/border-top-color.srb -->
<!-- #include src=properties/border-color.srb -->
<P>The <span class="propinst-border-color">'border-color'</span>
property sets the color of the four borders. Values have the following
meanings:</p>
<dl>
<dt><span class="index-inst" title="&lt;color&gt;"><span
class="value-inst-color"><strong>&lt;color&gt;</strong></span></span>
<dd>Specifies a color value.
<dt><strong>transparent</strong>
<dd>The border is transparent (though it may have width).
</dl>
<P>The <span class="propinst-border-color">'border-color'</span>
property can have from one to four component values, and the values
are set on the different sides as for <span
class="propinst-border-width">'border-width'</span>.
<P>If an element's border color is not specified
with a border property, user agents must use the value
of the element's <span
class="propinst-color">'color'</span> property as the
<a href="cascade.html#computed-value">computed value</a>
for the border color.
<div class="example">
<P>In this example, the border will be a solid black line.
<PRE>
p {
color: black;
background: white;
border: solid;
}
</PRE>
</div>
<H3><A name="border-style-properties">Border style</a>:
<span class="propinst-border-top-style">'border-top-style'</span>,
<span class="propinst-border-right-style">'border-right-style'</span>,
<span class="propinst-border-bottom-style">'border-bottom-style'</span>,
<span class="propinst-border-left-style">'border-left-style'</span>, and
<span class="propinst-border-style">'border-style'</span></H3>
<P>The border style properties specify the line style of a box's
border (solid, double, dashed, etc.). The properties defined in this
section refer to the <span class="index-def"
title="&lt;border-style&gt;, definition of"><a
name="value-def-border-style"><strong>&lt;border-style&gt;</strong></a></span>
value type, which may take one of the following values:</p>
<dl>
<dt><strong><span class="index-def" title="'none'::as border style"><a name="value-def-bo-none" class="value-def">none</a></span></strong>
<dd>No border; the computed border width is zero.
<dt><strong><span class="index-def" title="'hidden'"><a name="value-def-hidden" class="value-def">hidden</a></span></strong>
<dd>Same as 'none', except in terms of <a
href="tables.html#border-conflict-resolution">border conflict
resolution</a> for <a href="tables.html">table elements</a>.
<dt><strong><span class="index-def" title="'dotted'"><a name="value-def-dotted" class="value-def">dotted</a></span></strong>
<dd>The border is a series of dots.
<dt><strong><span class="index-def" title="'dashed'"><a name="value-def-dashed" class="value-def">dashed</a></span></strong>
<dd>The border is a series of short line segments.
<dt><strong><span class="index-def" title="'solid'"><a name="value-def-solid" class="value-def">solid</a></span></strong>
<dd>The border is a single line segment.
<dt><strong><span class="index-def" title="'double'"><a name="value-def-double" class="value-def">double</a></span></strong>
<dd>The border is two solid lines. The sum of
the two lines and the space between them
equals the value of <span
class="propinst-border-width">'border-width'</span>.
<dt><strong><span class="index-def" title="'groove'"><a name="value-def-groove" class="value-def">groove</a></span></strong>
<dd>The border looks as though it were carved
into the canvas.
<dt><strong><span class="index-def" title="'ridge'"><a name="value-def-ridge" class="value-def">ridge</a></span></strong>
<dd>The opposite of 'groove': the border
looks as though it were coming out of the canvas.
<dt><strong><span class="index-def" title="'inset'"><a name="value-def-inset" class="value-def">inset</a></span></strong>
<dd>The border makes the box look as though
it were embedded in the canvas.
<dt><strong><span class="index-def" title="'outset'"><a name="value-def-outset" class="value-def">outset</a></span></strong>
<dd>The opposite of 'inset': the
border makes the box look as though
it were coming out of the canvas.
</dl>
<P>All borders are drawn on top of the box's background. The color of
borders drawn for values of 'groove', 'ridge', 'inset', and 'outset'
depends on the element's <a href="#border-color-properties">border
color properties</a>, but UAs may choose their own algorithm to
calculate the actual colors used. For instance, if the 'border-color'
has the value 'silver', then a UA could use a gradient of colors from
white to dark gray to indicate a sloping border.
<!-- Remove? BB 29 Apr 2003
<P><span class="index-inst" title="conformance"><a
href="conform.html#conformance">Conforming HTML user agents</a></span> may
interpret 'dotted', 'dashed', 'double', 'groove', 'ridge',
'inset', and 'outset' to be 'solid'.
-->
<!-- #include src=properties/border-top-style.srb -->
<!-- #include src=properties/border-style.srb -->
<P> The <span class="propinst-border-style">'border-style'</span>
property sets the style of the four borders. It can have from one to
four component values, and the values are set on the different sides as for
<span class="propinst-border-width">'border-width'</span> above.
<div class="example"><P>
<PRE>
#xy34 { border-style: solid dotted }
</PRE>
<P> In the above example, the horizontal borders will be 'solid' and
the vertical borders will be 'dotted'.
</div>
<P> Since the initial value of the border styles is 'none', no borders
will be visible unless the border style is set.
<H3><A name="border-shorthand-properties">Border shorthand properties</a>:
<span class="propinst-border-top">'border-top'</span>,
<span class="propinst-border-right">'border-right'</span>,
<span class="propinst-border-bottom">'border-bottom'</span>,
<span class="propinst-border-left">'border-left'</span>, and
<span class="propinst-border">'border'</span></h3>
<!-- #include src=properties/border-top.srb -->
<P> This is a shorthand property for setting the width, style, and
color of the top, right, bottom, and left border of a box.
<div class="example"><P>
<PRE>
h1 { border-bottom: thick solid red }
</PRE>
<P> The above rule will set the width, style, and color of the border
<strong>below</strong> the H1 element. Omitted values are set to
their <a href="about.html#initial-value">initial values</a>. Since
the following rule does not specify a border color, the border will
have the color specified by the <span class="propinst-color">
'color'</span> property:
<PRE>
H1 { border-bottom: thick solid }
</PRE>
</div>
<!-- #include src=properties/border.srb -->
<P> The <span class="propinst-border">'border'</span> property is a
shorthand property for setting the same width, color, and style for
all four borders of a box. Unlike the shorthand <span
class="propinst-margin">'margin'</span> and <span
class="propinst-padding">'padding'</span> properties, the <span
class="propinst-border">'border'</span> property cannot set different
values on the four borders. To do so, one or more of the other border
properties must be used.
<div class="example"><P>
For example, the first rule below is
equivalent to the set of four rules shown after it:
<PRE>
p { border: solid red }
p {
border-top: solid red;
border-right: solid red;
border-bottom: solid red;
border-left: solid red
}
</PRE>
</div>
<P> Since, to some extent, the properties have overlapping
functionality, the order in which the rules are specified is
important.
<div class="example"><P>
Consider this example:
<PRE>
blockquote {
border: solid red;
border-left: double;
color: black;
}
</PRE>
<P> In the above example, the color of the left border is black,
while the other borders are red. This is due to <span
class="propinst-border-left">'border-left'</span> setting the
width, style, and color. Since the color value is not given by the
<span class="propinst-border-left">'border-left'</span> property, it
will be taken from the <span class="propinst-color">'color'</span>
property. The fact that the <span
class="propinst-color">'color'</span> property is set after the <span
class="propinst-border-left">'border-left'</span> property is not
relevant.
</div>
<h2><a name="bidi-box-model">The box model for inline elements in bidirectional context</a></h2>
<p>For each line box, UAs must take the inline boxes generated for
each element and render the margins, borders and padding in visual
order (not logical order).
<p>When the element's <span
class=propinst-direction>'direction'</span> property is 'ltr', the
left-most generated box of the first line box in which the element
appears has the left margin, left border and left padding, and the
right-most generated box of the last line box in which the element
appears has the right padding, right border and right margin.
<p>When the element's <span
class=propinst-direction>'direction'</span> property is 'rtl', the
right-most generated box of the first line box in which the element
appears has the right padding, right border and right margin, and the
left-most generated box of the last line box in which the element
appears has the left margin, left border and left padding.
</BODY>
</HTML>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-declaration:"~/SGML/HTML4.dcl"
sgml-default-doctype-name:"html"
sgml-minimize-attributes:t
End:
-->