This chapter shows how box model properties style the various types of boxes. These are basic design patterns.
The Margin, Border, and Padding design patterns contain examples contrasting how each property works in each type of box. Their main purpose is to contrast in one place how the same property means different things in different contexts. When using this book as a reference, you may also want to refer to the Margin, Border, and Padding design patterns to determine which type of element, box, and property will do what you want.
*.before { margin:0; }
*.after { margin-top:10px; margin-bottom:0;
margin-left:30px; margin-right:10px; }
/* Nonessential rules are not shown.
HTML code is omitted to allow the example to fit on one page. */
*.before { border:1px solid black; }
*.after { border-top:10px solid dimgray; border-bottom:1px solid black;
border-left:30px solid black; border-right:5px solid black; }
/* Nonessential rules are not shown.
HTML code is omitted to allow the example to fit on one page. */
*.before { padding:0; }
*.after { padding-top:10px; padding-bottom:0;
padding-left:30px; padding-right:10px; }
/* Nonessential rules are not shown.
HTML code is omitted to allow the example to fit on one page. */
<h1>Background</h1>
<p><span class="no-bg"> </span>No background</p>
<p><span class="bg-color"> </span>Background color</p>
<p><span class="bg-image"> </span>Background image not tiled</p>
<p><span class="bg-repeat"> </span>Background image tiled</p>
<p><span class="bg-rx"> </span>Background image repeat-x</p>
<p><span class="bg-ry"> </span>Background image repeat-y →</p>
<p><span class="bg-pos-lt"> </span>Background image center bottom</p>
<p><span class="bg-pos-rb"> </span>Background image right bottom</p>
p { margin-left:240px; margin-top:0px; margin-bottom:10px; }
span { margin-left:-230px; margin-right:30px; padding-left:195px; font-size:19px;
background-position:left bottom; background-repeat:no-repeat;
background-color:black; background-image:url("star.gif"); }
*.no-bg { background-image:none; background-color:transparent; }
*.bg-color { background-image:none; background-color:black; }
*.bg-image { background-repeat:no-repeat; }
*.bg-repeat { background-repeat:repeat; }
*.bg-rx { background-repeat:repeat-x; }
*.bg-pos-lt { background-position:center bottom; }
*.bg-pos-rb { background-position:right bottom; }
*.bg-ry { background-repeat:repeat-y; background-position:center top;
padding-left:22px; float:right; height:263px; margin:0px;
position:relative; top:-170px; }
<div id="ex1">
<h1><code>overflow:visible</code></h1>
<p class="ex1" >
<span class="big">OVERFLOW</span> <br />
<span class="nowrap">The text in this span does not wrap!</span>
<select size="2">
<option>select me</option>
<option selected="selected">select me</option>
</select><br />
<span>Vertical Overflow.</span>
</p>
</div>
*.ex1 { overflow:visible; }
*.ex2 { overflow:hidden; }
*.ex3 { overflow:scroll; }
*.ex4 { overflow:auto; }
/* Nonessential rules are not shown. */
<h1>Visibility</h1>
<p>There is hidden content here: <span class="hidden">CAN YOU SEE ME NOW?</span>
You can't see it, because it's styled with <code>visibility:hidden</code>,
but you can see where it would have been rendered. </p>
<p>There is visible content here: <span class="visible">CAN YOU SEE ME NOW?</span> You can see
it, because it's styled with <code>visibility:visible</code>. </p>
span { padding:4px; background-color:white;
border-left:1px solid gray; border-right:2px solid black;
border-top:1px solid gray; border-bottom:2px solid black; }
p { background-color:gold; padding:10px; line-height:1.5em; }
*.hidden { visibility:hidden; }
*.visible { visibility:visible; }
span:hover { visibility:hidden; }
<div class="page-break-after">Page break after this element. </div>
<div class="page-break-after">Page break after this element. </div>
<div class="page-break-before">Page break before this element.</div>
*.page-break-before { page-break-before:always; }
*.page-break-after { page-break-after:always; }