CINXE.COM

Box model

<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01//EN'> <html lang="en"> <HEAD> <TITLE>Box model</TITLE> <link rel="stylesheet" href="style/default.css" type="text/css"> <link rel="stylesheet" href="https://www.w3.org/StyleSheets/TR/W3C-REC.css" type="text/css"> <link rel="prev" href="media.html"> <link rel="next" href="visuren.html"> <link rel="contents" href="cover.html#minitoc"> <link rel="CSS-properties" href="propidx.html" title="properties"> <link rel="index" href="indexlist.html" title="index"> <link rel="first" href="cover.html"> </HEAD> <BODY> <div class="navbar"> <p><a href="media.html">previous</a> &nbsp; <a href="visuren.html">next</a> &nbsp; <a href="cover.html#minitoc">contents</a> &nbsp; <a href="propidx.html">properties</a> &nbsp; <a href="indexlist.html">index</a> &nbsp; </div> <hr class="navbar"> <H1>8 <a name="box-model">Box model</a></H1> <div class="subtoc"> <p><strong>Contents</strong> <ul class="toc"> <li class="tocline2"><a href="box.html#box-dimensions" class="tocxref">8.1 Box dimensions</a> <li class="tocline2"><a href="box.html#mpb-examples" class="tocxref">8.2 Example of margins, padding, and borders</a> <li class="tocline2"><a href="box.html#margin-properties" class="tocxref">8.3 Margin properties: <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></a> <ul class="toc"> <li class="tocline3"><a href="box.html#collapsing-margins" class="tocxref">8.3.1 Collapsing margins</a> </ul> <li class="tocline2"><a href="box.html#padding-properties" class="tocxref">8.4 Padding properties: <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></a> <li class="tocline2"><a href="box.html#border-properties" class="tocxref">8.5 Border properties</a> <ul class="toc"> <li class="tocline3"><a href="box.html#border-width-properties" class="tocxref">8.5.1 Border width: <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></a> <li class="tocline3"><a href="box.html#border-color-properties" class="tocxref">8.5.2 Border color: <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></a> <li class="tocline3"><a href="box.html#border-style-properties" class="tocxref">8.5.3 Border style: <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></a> <li class="tocline3"><a href="box.html#border-shorthand-properties" class="tocxref">8.5.4 Border shorthand properties: <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></a> </ul> <li class="tocline2"><a href="box.html#bidi-box-model" class="tocxref">8.6 The box model for inline elements in bidirectional context</a> </ul> </div> <!-- warning --> <div> <input id=annoying-warning type=checkbox title="hide note"> <label for=annoying-warning>(hide)</label> <div class=annoying-warning> <p><strong>Note:</strong> Several sections of this specification have been updated by other specifications. Please, see <a href="https://www.w3.org/TR/CSS/#css" >"Cascading Style Sheets (CSS) &mdash; The Official Definition"</a> in the latest <cite>CSS Snapshot</cite> for a list of specifications and the sections they replace. <p>The CSS Working Group is also developing <a href="https://www.w3.org/TR/CSS22/">CSS level&nbsp;2 revision&nbsp;2 (CSS&nbsp;2.2).</a> </div> </div> <!-- /warning --> <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>8.1 <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."><SPAN class="dlink">&nbsp;&nbsp;&nbsp;<A name="img-boxdim" href="images/longdesc/boxdim-desc.html" title="Long description of illustration of box areas">[D]</A></SPAN></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><a name="x10"><span class="index-def">content box</span></a></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><a name="x12"><span class="index-def">padding box</span></a></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><a name="x14"><span class="index-def">border box</span></a></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><a name="x17"><span class="index-def">margin box</span></a></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 <a href="visudet.html#propdef-width" class="noxref"><span class="propinst-width">'width'</span></a> or <a href="visudet.html#propdef-height" class="noxref"><span class="propinst-height">'height'</span></a> 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 <a href="colors.html#propdef-background" class="noxref"><span class="propinst-background">'background'</span></a> property of the generating element. Margin backgrounds are always transparent. <H2>8.2 <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."><SPAN class="dlink">&nbsp;&nbsp;&nbsp;<A name="img-boxdimeg" href="images/longdesc/boxdimeg-desc.html" title="Long description of list box example showing margins, padding, and borders">[D]</A></SPAN></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 <a href="box.html#propdef-padding" class="noxref"><span class="propinst-padding">'padding'</span></a> 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 <a href="box.html#propdef-border-style" class="noxref"><span class="propinst-border-style">'border-style'</span></a> property). </ul> <H2>8.3 <a name="margin-properties">Margin properties</a>: <a href="box.html#propdef-margin-top" class="noxref"><span class="propinst-margin-top">'margin-top'</span></a>, <a href="box.html#propdef-margin-right" class="noxref"><span class="propinst-margin-right">'margin-right'</span></a>, <a href="box.html#propdef-margin-bottom" class="noxref"><span class="propinst-margin-bottom">'margin-bottom'</span></a>, <a href="box.html#propdef-margin-left" class="noxref"><span class="propinst-margin-left">'margin-left'</span></a>, and <a href="box.html#propdef-margin" class="noxref"><span class="propinst-margin">'margin'</span></a></H2> <P>Margin properties specify the width of the <a href="#box-margin-area">margin area</a> of a box. The <a href="box.html#propdef-margin" class="noxref"><span class="propinst-margin">'margin'</span></a> 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><a href="syndata.html#value-def-length" class="noxref"><span class="value-inst-length"><strong>&lt;length&gt;</strong></span></a> <dd>Specifies a fixed width. <dt><a href="syndata.html#value-def-percentage" class="noxref"><span class="value-inst-percentage"><strong>&lt;percentage&gt;</strong></span></a> <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 <a href="box.html#propdef-margin-top" class="noxref"><span class="propinst-margin-top">'margin-top'</span></a> and <a href="box.html#propdef-margin-bottom" class="noxref"><span class="propinst-margin-bottom">'margin-bottom'</span></a> 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. <div class="propdef"> <dl><dt> <span class="index-def" title="'margin-top'"><a name="propdef-margin-top" class="propdef-title"><strong>'margin-top'</strong></a></span>, <span class="index-def" title="'margin-bottom'"><a name="propdef-margin-bottom" class="propdef-title"><strong>'margin-bottom'</strong></a></span> <dd> <table class="propinfo" cellspacing=0 cellpadding=0> <tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td><a href="box.html#value-def-margin-width" class="noxref"><span class="value-inst-margin-width">&lt;margin-width&gt;</span></a> | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a> <tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>0 <tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements except elements with table display types other than table-caption, table and inline-table <tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no <tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>refer to width of containing block <tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a> <tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>the percentage as specified or the absolute length </table> </dl> </div> <p class="note">These properties have no effect on non-replaced inline elements.</p> <div class="propdef"> <dl><dt> <span class="index-def" title="'margin-right'"><a name="propdef-margin-right" class="propdef-title"><strong>'margin-right'</strong></a></span>, <span class="index-def" title="'margin-left'"><a name="propdef-margin-left" class="propdef-title"><strong>'margin-left'</strong></a></span> <dd> <table class="propinfo" cellspacing=0 cellpadding=0> <tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td><a href="box.html#value-def-margin-width" class="noxref"><span class="value-inst-margin-width">&lt;margin-width&gt;</span></a> | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a> <tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>0 <tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements except elements with table display types other than table-caption, table and inline-table <tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no <tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>refer to width of containing block <tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a> <tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>the percentage as specified or the absolute length </table> </dl> </div> <P>These properties set the top, right, bottom, and left margin of a box. <div class="example"><P style="display:none">Example(s):</P><P> <PRE> h1 { margin-top: 2em } </PRE> </div> <div class="propdef"> <dl><dt> <span class="index-def" title="'margin'"><a name="propdef-margin" class="propdef-title"><strong>'margin'</strong></a></span> <dd> <table class="propinfo" cellspacing=0 cellpadding=0> <tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td><a href="box.html#value-def-margin-width" class="noxref"><span class="value-inst-margin-width">&lt;margin-width&gt;</span></a>{1,4} | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a> <tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>see individual properties <tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements except elements with table display types other than table-caption, table and inline-table <tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no <tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>refer to width of containing block <tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a> <tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>see individual properties </table> </dl> </div> <P> The <a href="box.html#propdef-margin" class="noxref"><span class="propinst-margin">'margin'</span></a> property is a shorthand property for setting <a href="box.html#propdef-margin-top" class="noxref"><span class="propinst-margin-top">'margin-top'</span></a>, <a href="box.html#propdef-margin-right" class="noxref"><span class="propinst-margin-right">'margin-right'</span></a>, <a href="box.html#propdef-margin-bottom" class="noxref"><span class="propinst-margin-bottom">'margin-bottom'</span></a>, and <a href="box.html#propdef-margin-left" class="noxref"><span class="propinst-margin-left">'margin-left'</span></a> 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 style="display:none">Example(s):</P><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>8.3.1 <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><a name="x26"><span class="index-def">collapse</span></a></dfn>, and the resulting combined margin is called a <dfn><a name="x27"><span class="index-def" title="collapsing margin">collapsed margin</span></a></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. </UL> <P>Horizontal margins never collapse. <P ID="what-is-adjoining">Two margins are <a name="x28"><span class="index-def" title="adjoining margins"><DFN>adjoining</DFN></span></a> 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 <a href="visudet.html#propdef-min-height" class="noxref"><span class="propinst-min-height">'min-height'</span></a>, zero or 'auto' computed <a href="visudet.html#propdef-height" class="noxref"><span class="propinst-height">'height'</span></a>, 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 <a href="visufx.html#propdef-overflow" class="noxref"><span class="propinst-overflow">'overflow'</span></a> 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 <a href="visudet.html#propdef-height" class="noxref"><span class="propinst-height">'height'</span></a> of 'auto' and a <a href="visudet.html#propdef-min-height" class="noxref"><span class="propinst-min-height">'min-height'</span></a> of zero collapses with its last in-flow block-level child's bottom margin if the box has no bottom padding and no bottom border and the child's bottom margin does not collapse with a top margin that has clearance. <LI>A box's own margins collapse if the <a href="visudet.html#propdef-min-height" class="noxref"><span class="propinst-min-height">'min-height'</span></a> property is zero, and it has neither top or bottom borders nor top or bottom padding, and it has a <a href="visudet.html#propdef-height" class="noxref"><span class="propinst-height">'height'</span></a> 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><a name="x29"><span class="index-def">collapse through</span></a></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>8.4 <a name="padding-properties">Padding properties</a>: <a href="box.html#propdef-padding-top" class="noxref"><span class="propinst-padding-top">'padding-top'</span></a>, <a href="box.html#propdef-padding-right" class="noxref"><span class="propinst-padding-right">'padding-right'</span></a>, <a href="box.html#propdef-padding-bottom" class="noxref"><span class="propinst-padding-bottom">'padding-bottom'</span></a>, <a href="box.html#propdef-padding-left" class="noxref"><span class="propinst-padding-left">'padding-left'</span></a>, and <a href="box.html#propdef-padding" class="noxref"><span class="propinst-padding">'padding'</span></a> </H2> <P>The padding properties specify the width of the <a href="#box-padding-area">padding area</a> of a box. The <a href="box.html#propdef-padding" class="noxref"><span class="propinst-padding">'padding'</span></a> 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><a href="syndata.html#value-def-length" class="noxref"><span class="value-inst-length"><strong>&lt;length&gt;</strong></span></a> <dd>Specifies a fixed width. <dt><a href="syndata.html#value-def-percentage" class="noxref"><span class="value-inst-percentage"><strong>&lt;percentage&gt;</strong></span></a> <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 <a href="box.html#propdef-padding-top" class="noxref"><span class="propinst-padding-top">'padding-top'</span></a> and <a href="box.html#propdef-padding-bottom" class="noxref"><span class="propinst-padding-bottom">'padding-bottom'</span></a>. 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. <div class="propdef"> <dl><dt> <span class="index-def" title="'padding-top'"><a name="propdef-padding-top" class="propdef-title"><strong>'padding-top'</strong></a></span>, <span class="index-def" title="'padding-right'"><a name="propdef-padding-right" class="propdef-title"><strong>'padding-right'</strong></a></span>, <span class="index-def" title="'padding-bottom'"><a name="propdef-padding-bottom" class="propdef-title"><strong>'padding-bottom'</strong></a></span>, <span class="index-def" title="'padding-left'"><a name="propdef-padding-left" class="propdef-title"><strong>'padding-left'</strong></a></span> <dd> <table class="propinfo" cellspacing=0 cellpadding=0> <tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td><a href="box.html#value-def-padding-width" class="noxref"><span class="value-inst-padding-width">&lt;padding-width&gt;</span></a> | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a> <tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>0 <tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements except table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column <tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no <tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>refer to width of containing block <tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a> <tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>the percentage as specified or the absolute length </table> </dl> </div> <P>These properties set the top, right, bottom, and left padding of a box. <div class="example"><P style="display:none">Example(s):</P><P> <PRE> blockquote { padding-top: 0.3em } </PRE> </div> <div class="propdef"> <dl><dt> <span class="index-def" title="'padding'"><a name="propdef-padding" class="propdef-title"><strong>'padding'</strong></a></span> <dd> <table class="propinfo" cellspacing=0 cellpadding=0> <tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td><a href="box.html#value-def-padding-width" class="noxref"><span class="value-inst-padding-width">&lt;padding-width&gt;</span></a>{1,4} | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a> <tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>see individual properties <tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements except table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column <tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no <tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>refer to width of containing block <tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a> <tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>see individual properties </table> </dl> </div> <P> The <a href="box.html#propdef-padding" class="noxref"><span class="propinst-padding">'padding'</span></a> property is a shorthand property for setting <a href="box.html#propdef-padding-top" class="noxref"><span class="propinst-padding-top">'padding-top'</span></a>, <a href="box.html#propdef-padding-right" class="noxref"><span class="propinst-padding-right">'padding-right'</span></a>, <a href="box.html#propdef-padding-bottom" class="noxref"><span class="propinst-padding-bottom">'padding-bottom'</span></a>, and <a href="box.html#propdef-padding-left" class="noxref"><span class="propinst-padding-left">'padding-left'</span></a> 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 <a href="colors.html#propdef-background" class="noxref"><span class="propinst-background">'background'</span></a> property: <div class="example"><P style="display:none">Example(s):</P><P> <PRE> h1 { background: white; padding: 1em 2em; } </PRE> <P> The example above specifies a '1em' vertical padding (<a href="box.html#propdef-padding-top" class="noxref"><span class="propinst-padding-top">'padding-top'</span></a> and <a href="box.html#propdef-padding-bottom" class="noxref"><span class="propinst-padding-bottom">'padding-bottom'</span></a>) and a '2em' horizontal padding (<a href="box.html#propdef-padding-right" class="noxref"><span class="propinst-padding-right">'padding-right'</span></a> and <a href="box.html#propdef-padding-left" class="noxref"><span class="propinst-padding-left">'padding-left'</span></a>). 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>8.5 <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>8.5.1 <a name="border-width-properties">Border width</A>: <a href="box.html#propdef-border-top-width" class="noxref"><span class="propinst-border-top-width">'border-top-width'</span></a>, <a href="box.html#propdef-border-right-width" class="noxref"><span class="propinst-border-right-width">'border-right-width'</span></a>, <a href="box.html#propdef-border-bottom-width" class="noxref"><span class="propinst-border-bottom-width">'border-bottom-width'</span></a>, <a href="box.html#propdef-border-left-width" class="noxref"><span class="propinst-border-left-width">'border-left-width'</span></a>, and <a href="box.html#propdef-border-width" class="noxref"><span class="propinst-border-width">'border-width'</span></a></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><a href="syndata.html#value-def-length" class="noxref"><span class="value-inst-length"><strong>&lt;length&gt;</strong></span></a> <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. <div class="propdef"> <dl><dt> <span class="index-def" title="'border-top-width'"><a name="propdef-border-top-width" class="propdef-title"><strong>'border-top-width'</strong></a></span>, <span class="index-def" title="'border-right-width'"><a name="propdef-border-right-width" class="propdef-title"><strong>'border-right-width'</strong></a></span>, <span class="index-def" title="'border-bottom-width'"><a name="propdef-border-bottom-width" class="propdef-title"><strong>'border-bottom-width'</strong></a></span>, <span class="index-def" title="'border-left-width'"><a name="propdef-border-left-width" class="propdef-title"><strong>'border-left-width'</strong></a></span> <dd> <table class="propinfo" cellspacing=0 cellpadding=0> <tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td><a href="box.html#value-def-border-width" class="noxref"><span class="value-inst-border-width">&lt;border-width&gt;</span></a> | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a> <tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>medium <tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements <tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no <tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>N/A <tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a> <tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>absolute length; '0' if the border style is 'none' or 'hidden' </table> </dl> </div> <P>These properties set the width of the top, right, bottom, and left border of a box. <div class="propdef"> <dl><dt> <span class="index-def" title="'border-width'"><a name="propdef-border-width" class="propdef-title"><strong>'border-width'</strong></a></span> <dd> <table class="propinfo" cellspacing=0 cellpadding=0> <tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td><a href="box.html#value-def-border-width" class="noxref"><span class="value-inst-border-width">&lt;border-width&gt;</span></a>{1,4} | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a> <tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>see individual properties <tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements <tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no <tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>N/A <tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a> <tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>see individual properties </table> </dl> </div> <P> This property is a shorthand property for setting <a href="box.html#propdef-border-top-width" class="noxref"><span class="propinst-border-top-width">'border-top-width'</span></a>, <a href="box.html#propdef-border-right-width" class="noxref"><span class="propinst-border-right-width">'border-right-width'</span></a>, <a href="box.html#propdef-border-bottom-width" class="noxref"><span class="propinst-border-bottom-width">'border-bottom-width'</span></a>, and <a href="box.html#propdef-border-left-width" class="noxref"><span class="propinst-border-left-width">'border-left-width'</span></a> 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 style="display:none">Example(s):</P><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>8.5.2 <A name="border-color-properties">Border color</A>: <a href="box.html#propdef-border-top-color" class="noxref"><span class="propinst-border-top-color">'border-top-color'</span></a>, <a href="box.html#propdef-border-right-color" class="noxref"><span class="propinst-border-right-color">'border-right-color'</span></a>, <a href="box.html#propdef-border-bottom-color" class="noxref"><span class="propinst-border-bottom-color">'border-bottom-color'</span></a>, <a href="box.html#propdef-border-left-color" class="noxref"><span class="propinst-border-left-color">'border-left-color'</span></a>, and <a href="box.html#propdef-border-color" class="noxref"><span class="propinst-border-color">'border-color'</span></a> </H3> <P>The border color properties specify the color of a box's border. <div class="propdef"> <dl><dt> <span class="index-def" title="'border-top-color'"><a name="propdef-border-top-color" class="propdef-title"><strong>'border-top-color'</strong></a></span>, <span class="index-def" title="'border-right-color'"><a name="propdef-border-right-color" class="propdef-title"><strong>'border-right-color'</strong></a></span>, <span class="index-def" title="'border-bottom-color'"><a name="propdef-border-bottom-color" class="propdef-title"><strong>'border-bottom-color'</strong></a></span>, <span class="index-def" title="'border-left-color'"><a name="propdef-border-left-color" class="propdef-title"><strong>'border-left-color'</strong></a></span> <dd> <table class="propinfo" cellspacing=0 cellpadding=0> <tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td><a href="syndata.html#value-def-color" class="noxref"><span class="value-inst-color">&lt;color&gt;</span></a> | transparent | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a> <tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>the value of the 'color' property <tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements <tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no <tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>N/A <tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a> <tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>when taken from the 'color' property, the computed value of 'color'; otherwise, as specified </table> </dl> </div> <div class="propdef"> <dl><dt> <span class="index-def" title="'border-color'"><a name="propdef-border-color" class="propdef-title"><strong>'border-color'</strong></a></span> <dd> <table class="propinfo" cellspacing=0 cellpadding=0> <tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td>[ <a href="syndata.html#value-def-color" class="noxref"><span class="value-inst-color">&lt;color&gt;</span></a> | transparent ]{1,4} | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a> <tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>see individual properties <tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements <tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no <tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>N/A <tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a> <tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>see individual properties </table> </dl> </div> <P>The <a href="box.html#propdef-border-color" class="noxref"><span class="propinst-border-color">'border-color'</span></a> property sets the color of the four borders. Values have the following meanings:</p> <dl> <dt><span class="index-inst" title="&lt;color&gt;"><a name="x47" href="syndata.html#value-def-color" class="noxref"><span class="value-inst-color"><strong>&lt;color&gt;</strong></span></a></span> <dd>Specifies a color value. <dt><strong>transparent</strong> <dd>The border is transparent (though it may have width). </dl> <P>The <a href="box.html#propdef-border-color" class="noxref"><span class="propinst-border-color">'border-color'</span></a> property can have from one to four component values, and the values are set on the different sides as for <a href="box.html#propdef-border-width" class="noxref"><span class="propinst-border-width">'border-width'</span></a>. <P>If an element's border color is not specified with a border property, user agents must use the value of the element's <a href="colors.html#propdef-color" class="noxref"><span class="propinst-color">'color'</span></a> property as the <a href="cascade.html#computed-value">computed value</a> for the border color. <div class="example"><P style="display:none">Example(s):</P> <P>In this example, the border will be a solid black line. <PRE> p { color: black; background: white; border: solid; } </PRE> </div> <H3>8.5.3 <A name="border-style-properties">Border style</a>: <a href="box.html#propdef-border-top-style" class="noxref"><span class="propinst-border-top-style">'border-top-style'</span></a>, <a href="box.html#propdef-border-right-style" class="noxref"><span class="propinst-border-right-style">'border-right-style'</span></a>, <a href="box.html#propdef-border-bottom-style" class="noxref"><span class="propinst-border-bottom-style">'border-bottom-style'</span></a>, <a href="box.html#propdef-border-left-style" class="noxref"><span class="propinst-border-left-style">'border-left-style'</span></a>, and <a href="box.html#propdef-border-style" class="noxref"><span class="propinst-border-style">'border-style'</span></a></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 <a href="box.html#propdef-border-width" class="noxref"><span class="propinst-border-width">'border-width'</span></a>. <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. <div class="propdef"> <dl><dt> <span class="index-def" title="'border-top-style'"><a name="propdef-border-top-style" class="propdef-title"><strong>'border-top-style'</strong></a></span>, <span class="index-def" title="'border-right-style'"><a name="propdef-border-right-style" class="propdef-title"><strong>'border-right-style'</strong></a></span>, <span class="index-def" title="'border-bottom-style'"><a name="propdef-border-bottom-style" class="propdef-title"><strong>'border-bottom-style'</strong></a></span>, <span class="index-def" title="'border-left-style'"><a name="propdef-border-left-style" class="propdef-title"><strong>'border-left-style'</strong></a></span> <dd> <table class="propinfo" cellspacing=0 cellpadding=0> <tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td><a href="box.html#value-def-border-style" class="noxref"><span class="value-inst-border-style">&lt;border-style&gt;</span></a> | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a> <tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>none <tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements <tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no <tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>N/A <tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a> <tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>as specified </table> </dl> </div> <div class="propdef"> <dl><dt> <span class="index-def" title="'border-style'"><a name="propdef-border-style" class="propdef-title"><strong>'border-style'</strong></a></span> <dd> <table class="propinfo" cellspacing=0 cellpadding=0> <tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td><a href="box.html#value-def-border-style" class="noxref"><span class="value-inst-border-style">&lt;border-style&gt;</span></a>{1,4} | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a> <tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>see individual properties <tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements <tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no <tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>N/A <tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a> <tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>see individual properties </table> </dl> </div> <P> The <a href="box.html#propdef-border-style" class="noxref"><span class="propinst-border-style">'border-style'</span></a> 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 <a href="box.html#propdef-border-width" class="noxref"><span class="propinst-border-width">'border-width'</span></a> above. <div class="example"><P style="display:none">Example(s):</P><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>8.5.4 <A name="border-shorthand-properties">Border shorthand properties</a>: <a href="box.html#propdef-border-top" class="noxref"><span class="propinst-border-top">'border-top'</span></a>, <a href="box.html#propdef-border-right" class="noxref"><span class="propinst-border-right">'border-right'</span></a>, <a href="box.html#propdef-border-bottom" class="noxref"><span class="propinst-border-bottom">'border-bottom'</span></a>, <a href="box.html#propdef-border-left" class="noxref"><span class="propinst-border-left">'border-left'</span></a>, and <a href="box.html#propdef-border" class="noxref"><span class="propinst-border">'border'</span></a></h3> <div class="propdef"> <dl><dt> <span class="index-def" title="'border-top'"><a name="propdef-border-top" class="propdef-title"><strong>'border-top'</strong></a></span>, <span class="index-def" title="'border-right'"><a name="propdef-border-right" class="propdef-title"><strong>'border-right'</strong></a></span>, <span class="index-def" title="'border-bottom'"><a name="propdef-border-bottom" class="propdef-title"><strong>'border-bottom'</strong></a></span>, <span class="index-def" title="'border-left'"><a name="propdef-border-left" class="propdef-title"><strong>'border-left'</strong></a></span> <dd> <table class="propinfo" cellspacing=0 cellpadding=0> <tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td>[ <a href="box.html#value-def-border-width" class="noxref"><span class="value-inst-border-width">&lt;border-width&gt;</span></a> || <a href="box.html#value-def-border-style" class="noxref"><span class="value-inst-border-style">&lt;border-style&gt;</span></a> || <a href="box.html#propdef-border-top-color" class="noxref"><span class="propinst-border-top-color">&lt;'border-top-color'&gt;</span></a> ] | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a> <tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>see individual properties <tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements <tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no <tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>N/A <tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a> <tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>see individual properties </table> </dl> </div> <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 style="display:none">Example(s):</P><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 <a href="colors.html#propdef-color" class="noxref"><span class="propinst-color"> 'color'</span></a> property: <PRE> H1 { border-bottom: thick solid } </PRE> </div> <div class="propdef"> <dl><dt> <span class="index-def" title="'border'"><a name="propdef-border" class="propdef-title"><strong>'border'</strong></a></span> <dd> <table class="propinfo" cellspacing=0 cellpadding=0> <tr valign=baseline><td><em>Value:</em>&nbsp;&nbsp;<td>[ <a href="box.html#value-def-border-width" class="noxref"><span class="value-inst-border-width">&lt;border-width&gt;</span></a> || <a href="box.html#value-def-border-style" class="noxref"><span class="value-inst-border-style">&lt;border-style&gt;</span></a> || <a href="box.html#propdef-border-top-color" class="noxref"><span class="propinst-border-top-color">&lt;'border-top-color'&gt;</span></a> ] | <a href="cascade.html#value-def-inherit" class="noxref"><span class="value-inst-inherit">inherit</span></a> <tr valign=baseline><td><em>Initial:</em>&nbsp;&nbsp;<td>see individual properties <tr valign=baseline><td><em>Applies to:</em>&nbsp;&nbsp;<td>all elements <tr valign=baseline><td><em>Inherited:</em>&nbsp;&nbsp;<td>no <tr valign=baseline><td><em>Percentages:</em>&nbsp;&nbsp;<td>N/A <tr valign=baseline><td><em>Media:</em>&nbsp;&nbsp;<td><a href="media.html#visual-media-group" class="noxref">visual</a> <tr valign=baseline><td><em>Computed&nbsp;value:</em>&nbsp;&nbsp;<td>see individual properties </table> </dl> </div> <P> The <a href="box.html#propdef-border" class="noxref"><span class="propinst-border">'border'</span></a> property is a shorthand property for setting the same width, color, and style for all four borders of a box. Unlike the shorthand <a href="box.html#propdef-margin" class="noxref"><span class="propinst-margin">'margin'</span></a> and <a href="box.html#propdef-padding" class="noxref"><span class="propinst-padding">'padding'</span></a> properties, the <a href="box.html#propdef-border" class="noxref"><span class="propinst-border">'border'</span></a> 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 style="display:none">Example(s):</P><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 style="display:none">Example(s):</P><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 <a href="box.html#propdef-border-left" class="noxref"><span class="propinst-border-left">'border-left'</span></a> setting the width, style, and color. Since the color value is not given by the <a href="box.html#propdef-border-left" class="noxref"><span class="propinst-border-left">'border-left'</span></a> property, it will be taken from the <a href="colors.html#propdef-color" class="noxref"><span class="propinst-color">'color'</span></a> property. The fact that the <a href="colors.html#propdef-color" class="noxref"><span class="propinst-color">'color'</span></a> property is set after the <a href="box.html#propdef-border-left" class="noxref"><span class="propinst-border-left">'border-left'</span></a> property is not relevant. </div> <h2>8.6 <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 <a href="visuren.html#propdef-direction" class="noxref"><span class=propinst-direction>'direction'</span></a> 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 <a href="visuren.html#propdef-direction" class="noxref"><span class=propinst-direction>'direction'</span></a> 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. <hr class="navbar"> <div class="navbar"> <p><a href="media.html">previous</a> &nbsp; <a href="visuren.html">next</a> &nbsp; <a href="cover.html#minitoc">contents</a> &nbsp; <a href="propidx.html">properties</a> &nbsp; <a href="indexlist.html">index</a> &nbsp; </div> </BODY> </HTML>

Pages: 1 2 3 4 5 6 7 8 9 10