spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

Boxing with CSS, Part I: The Theory

Boxing


Developer News
Sir Tim Talks Up Linked Open Data Movement
From L.A. to Vegas With 100GbE
Salesforce Rolls Out Big Summer '08 Update

CSS supposes that a document is displayed in various boxes. You can have boxes within another box, but the basic building block of a rendered document is a box.

Dissecting a Box

A box consists firstly of the content, that is, the stuff it actually displays. A box can, optionally, have a border and a background. A border is a decorative line around the box's contents, and the background is simply a backdrop to the box.

The content of a box is at the center of the box. Around the content is an area called the padding, which is the space between the content and the border. The border is around the padding. And around the border is the margin, which is the space between the box and other boxes around it. Figure 1 should illustrate this pretty clearly.

Figure 1: The Box Model

Displaying a Box

The background of a box is shown behind the content and the padding only. The margins are always transparent. So, a box with a green background and a blue border would be displayed as shown in Figure 2.

Figure 2: Displaying a Box

A box's margin, border or padding can be set to 0, in which case they are not displayed. The width of the margin, border or padding can be different in the top, bottom, left or right sides of the box. The box in figure three has a zero-width left and right border, zero padding on all sides, and a larger margin on the bottom than on the other three sides.

Figure 3: Another Box

You may have wondered why you haven't seen any of this in your documents so far. The answer is that since the default border width for most elements is zero on all sides, and since the default background on most elements is transparent, the visual effect is something like the one displayed in figure 4 (the grey line between the margin and padding is only meant to show the boundary; it is not actually displayed).

Figure 4: A Typical Box

So even though the margin and padding are there, they are both transparent, and most of the time they are also set to 0, so you only get the content occupying the whole box. Now let's take a look at what the relationship between elements and boxes is, as well as how you put boxes together.

Front Page12345

http://www.internet.com

Produced by Stephanos Piperoglou


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
webref The latest from WebReference.com Browse >
Book Review: Head First JavaScript · Web Hosting Control Panels · Use Your Blog for Fast Search Engine Rankings
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
NetApp's Virtual Storage Strategy Crystallizes · F/MC Watch: A Cisco-Centric Approach · Olympic Time Trials Use Wi-Fi Mesh


All Rights Reserved. Legal Notices.

URL: http://www.webreference.com/html//
Created: Nov 18, 1998
Revised: Nov 18, 1998