The University of Texas at Austin- What Starts Here Changes the World
Services Navigation


Cell Padding and Spacing

We currently have the following table:
Menu for Monday
Breakfast Lunch Dinner
eggs sandwich steak
migas burger grilled salmon

The cells automatically adjust in size to accomodate the longest element in the row or column. However, we can use CSS to add additional space. The property for controlling space within a cell is padding.

The amount of cellpadding for a table is defined in the CSS for the table, header, and cell tags

Menu for Monday
Breakfast Lunch Dinner
eggs sandwich steak
migas burger grilled salmon

CSS Source

.tablePadding th, .tablePadding td { padding:10px; }


/* css for aligning the data cells */

.tableDataAlignment { text-align:center; }

/* css for setting the table's alignment */

.tableLocation {
margin:auto;
}

/* css for setting the caption's alignment */

.alignCaption {
margin: auto;
}

/* css for setting the table's border */

.tableBorder, .tableBorder th, .tableBorder td {
border-style:solid;
border-color:black;
border-width:1px
}

Another property that allows you to add additional space is border-spacing. If we used the same syntax as above with the border-spacing instead of padding, our table would look like this:
Menu for Monday
Breakfast Lunch Dinner
eggs sandwich steak
migas burger grilled salmon

CSS Source

.tableBorderSpacing { border-spacing:10px; }


/* css for aligning the data cells */

.tableDataAlignment { text-align:center; }

/* css for setting the table's alignment */

.tableLocation {
margin:auto;
}

/* css for setting the caption's alignment */

.alignCaption {
margin: auto;
}

/* css for setting the table's border */

.tableBorder, .tableBorder th, .tableBorder td {
border-style:solid;
border-color:black;
border-width:1px
}

Thus border-spacing refers to the amount of space we want between cells.


  Updated 2008 January 14
  Copyright | Privacy | Accessibility
  Comments to TeamWeb