Creating space between an element and its border

You want padding.

Here’s a link to a site that demonstrates “margin”, “border”, and “padding” for an element. http://css-tricks.com/the-css-box-model/

However, there used to be a problem with IE’s rendering of the box model and the “rest of the world” in that IE used a different mechanism to determine “overall width”. You need to understand that if you plan on supporting IE7 (two generations old) or older.

I imagine that using the “rest of the world” way will be sufficient for your needs.

For the rest of the world (and the sake of when that link no longer works) here’s an ascii version of the same diagram:

+----------------------------+
|                            |
|          margin            |
|                            |
|   *******border**********  |
|   *                     *  |
|   *      padding        *  |
|   *                     *  |
|   *   ---------------   *  |
|   *   ---------------   *  |
|   *   ---ELEMENT-----   *  |
|   *   ---------------   *  |
|   *   ---------------   *  |
|   *                     *  |
|   ***********************  |
|                            |
|                            |
+----------------------------+

Leave a Comment