1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
|
<!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="http://www.w3.org/StyleSheets/TR/W3C-CR.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>
<a href="visuren.html">next</a>
<a href="cover.html#minitoc">contents</a>
<a href="propidx.html">properties</a>
<a href="indexlist.html">index</a>
</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 bidirection context</a>
</ul>
</div>
<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"> <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 <a name="x10"><span class="index-def"><dfn>content box</dfn></span></a>.
<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 <a name="x12"><span class="index-def"><dfn>padding box</dfn></span></a>.
<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 <a name="x14"><span class="index-def"><dfn>border
box</dfn></span></a>.
<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 <a name="x17"><span class="index-def"><dfn>margin
box</dfn></span></a>.
</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 — 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> —
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">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML>
<HEAD>
<TITLE>Examples of margins, padding, and borders</TITLE>
<STYLE type="text/css">
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;
}
</STYLE>
</HEAD>
<BODY>
<UL>
<LI>First element of list
<LI class="withborder">Second element of list is
a bit longer to illustrate wrapping.
</UL>
</BODY>
</HTML>
</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"> <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="box.html#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="box.html#content-height">content height</a>, plus top and bottom
padding, borders, and margins. Note that vertical margins between the
LI boxes <a href="box.html#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 — margins are always
transparent — 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.html#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="<margin-width>::definition of"><a
name="value-def-margin-width"><strong><margin-width></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><length></strong></span></a>
<dd>Specifies a fixed width.
<dt><a href="syndata.html#value-def-percentage" class="noxref"><span class="value-inst-percentage"><strong><percentage></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 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> <td><a href="box.html#value-def-margin-width" class="noxref"><span class="value-inst-margin-width"><margin-width></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> <td>0
<tr valign=baseline><td><em>Applies to:</em> <td>all elements except elements with table display
types other than table-caption, table and inline-table
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>refer to width of containing block
<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed value:</em> <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> <td><a href="box.html#value-def-margin-width" class="noxref"><span class="value-inst-margin-width"><margin-width></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> <td>0
<tr valign=baseline><td><em>Applies to:</em> <td>all elements except elements with table display
types other than table-caption, table and inline-table
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>refer to width of containing block
<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed value:</em> <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> <td><a href="box.html#value-def-margin-width" class="noxref"><span class="value-inst-margin-width"><margin-width></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> <td>see individual properties
<tr valign=baseline><td><em>Applies to:</em> <td>all elements except elements with table display
types other than table-caption, table and inline-table
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>refer to width of containing block
<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed value:</em> <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 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 & bottom = 1em, right & 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 this specification, the expression <a name="x26"><span class="index-def"
title="collapsing margin"><dfn>collapsing margins</dfn></span></a> means
that adjoining margins (no non-empty content, padding or border areas
or <a href="visuren.html#clearance">clearance</a> separate them) of
two or more boxes (which may be next to one another or nested) combine
to form a single margin.
<P>In CSS 2.1, <a name="x27"><span class="index-inst" title="horizontal
margin|margin::horizontal">horizontal margins</span></a> never collapse.
<P><a name="x29"><span class="index-inst" title="vertical margin|margin::vertical">
Vertical margins</span></a> may collapse between certain boxes:</p>
<ul>
<li>Two or more adjoining vertical margins of <a
href="visuren.html#block-box">block</a> boxes in the <a
href="visuren.html#normal-flow">normal flow</a> collapse. The
resulting margin width is the maximum of the adjoining margin 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 absolute
maximum of the negative adjoining margins is deducted from zero.
<strong>Note.</strong> Adjoining boxes may be generated by
elements that are not related as siblings or ancestors.
<li>Vertical 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>Vertical 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</a>
positioned boxes do not collapse (not even with their
in-flow children).
<li>Margins of <a name="x31"><span class="index-inst">inline-block</span></a> elements
do not collapse (not even with their in-flow children).
<li id="collapsed-through">
If the top and bottom margins of a box are adjoining, then it is
possible for margins to collapse through 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>
<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.</li></ul>
<p>An element that has had <a
href="visuren.html#clearance">clearance</a> applied to it never
collapses its top margin with its parent block's bottom margin.</p>
<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.</p>
</li>
<li>Margins of the root element's box do not collapse.</li>
</ul>
<div id="what-is-adjoining">
<p>The bottom margin of an in-flow block-level element is always
adjoining to the top margin of its next in-flow block-level
sibling, unless that sibling has <a
href="visuren.html#clearance">clearance.</a></p>
<p>The top margin of an in-flow block-level element is adjoining to
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 <a
href="visuren.html#clearance">clearance.</a></p>
<p>The bottom margin of an in-flow block-level element with a 'height'
of 'auto' is adjoining to its last in-flow block-level child's bottom
margin if the element has no bottom padding or border.
<p>An element's own margins are adjoining 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) are adjoining.</p>
<p>When an element's own margins collapse, and that element has had
clearance applied to it, its top margin collapses with the adjoining
margins of subsequent siblings but that resulting margin does not
collapse with the bottom margin of the parent block.</p>
<p>Collapsing is based on the <em>used value</em> of <a href="box.html#propdef-padding" class="noxref"><span
class="propinst-padding">'padding'</span></a>, <a href="box.html#propdef-margin" class="noxref"><span
class="propinst-margin">'margin'</span></a>, and <a href="box.html#propdef-border" class="noxref"><span
class="propinst-border">'border'</span></a> (i.e., after resolving any
percentages). The collapsed margin is
calculated over the used value of the various margins.</p>
</div>
<P>Please
consult the <a href="box.html#mpb-examples">examples of margin, padding, and
borders</a> for an illustration of collapsed margins.
<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.html#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="<padding-width>::definition of"><a
name="value-def-padding-width"><strong><padding-width></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><length></strong></span></a>
<dd>Specifies a fixed width.
<dt><a href="syndata.html#value-def-percentage" class="noxref"><span class="value-inst-percentage"><strong><percentage></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 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> <td><a href="box.html#value-def-padding-width" class="noxref"><span class="value-inst-padding-width"><padding-width></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> <td>0
<tr valign=baseline><td><em>Applies to:</em> <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> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>refer to width of containing block
<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed value:</em> <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> <td><a href="box.html#value-def-padding-width" class="noxref"><span class="value-inst-padding-width"><padding-width></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> <td>see individual properties
<tr valign=baseline><td><em>Applies to:</em> <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> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>refer to width of containing block
<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed value:</em> <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 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.html#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.html#box-border-area">border area</a>. The properties
defined in this section refer to the <span class="index-def"
title="<border-width>::definition of"><a
name="value-def-border-width"
class="value-def"><strong><border-width></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><length></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' <='medium' <= '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> <td><a href="box.html#value-def-border-width" class="noxref"><span class="value-inst-border-width"><border-width></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> <td>medium
<tr valign=baseline><td><em>Applies to:</em> <td>all elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>N/A
<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed value:</em> <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> <td><a href="box.html#value-def-border-width" class="noxref"><span class="value-inst-border-width"><border-width></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> <td>see individual properties
<tr valign=baseline><td><em>Applies to:</em> <td>all elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>N/A
<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed value:</em> <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 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> <td><a href="syndata.html#value-def-color" class="noxref"><span class="value-inst-color"><color></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> <td>the value of the 'color' property
<tr valign=baseline><td><em>Applies to:</em> <td>all elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>N/A
<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed value:</em> <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> <td>[ <a href="syndata.html#value-def-color" class="noxref"><span class="value-inst-color"><color></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> <td>see individual properties
<tr valign=baseline><td><em>Applies to:</em> <td>all elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>N/A
<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed value:</em> <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="<color>"><a name="x49" href="syndata.html#value-def-color" class="noxref"><span
class="value-inst-color"><strong><color></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 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="<border-style>, definition of"><a
name="value-def-border-style"><strong><border-style></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="box.html#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> <td><a href="box.html#value-def-border-style" class="noxref"><span class="value-inst-border-style"><border-style></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> <td>none
<tr valign=baseline><td><em>Applies to:</em> <td>all elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>N/A
<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed value:</em> <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> <td><a href="box.html#value-def-border-style" class="noxref"><span class="value-inst-border-style"><border-style></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> <td>see individual properties
<tr valign=baseline><td><em>Applies to:</em> <td>all elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>N/A
<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed value:</em> <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 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> <td>[ <a href="box.html#value-def-border-width" class="noxref"><span class="value-inst-border-width"><border-width></span></a> || <a href="box.html#value-def-border-style" class="noxref"><span class="value-inst-border-style"><border-style></span></a> || <a href="box.html#propdef-border-top-color" class="noxref"><span class="propinst-border-top-color"><'border-top-color'></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> <td>see individual properties
<tr valign=baseline><td><em>Applies to:</em> <td>all elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>N/A
<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed value:</em> <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> <td>[ <a href="box.html#value-def-border-width" class="noxref"><span class="value-inst-border-width"><border-width></span></a> || <a href="box.html#value-def-border-style" class="noxref"><span class="value-inst-border-style"><border-style></span></a> || <a href="box.html#propdef-border-top-color" class="noxref"><span class="propinst-border-top-color"><'border-top-color'></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> <td>see individual properties
<tr valign=baseline><td><em>Applies to:</em> <td>all elements
<tr valign=baseline><td><em>Inherited:</em> <td>no
<tr valign=baseline><td><em>Percentages:</em> <td>N/A
<tr valign=baseline><td><em>Media:</em> <td><a href="media.html#visual-media-group" class="noxref">visual</a>
<tr valign=baseline><td><em>Computed value:</em> <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 bidirection 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>
<a href="visuren.html">next</a>
<a href="cover.html#minitoc">contents</a>
<a href="propidx.html">properties</a>
<a href="indexlist.html">index</a>
</div>
</BODY>
</HTML>
|