Skip to content

Instantly share code, notes, and snippets.

@gojomo
Created May 1, 2010 08:11
Show Gist options
  • Save gojomo/386146 to your computer and use it in GitHub Desktop.
Save gojomo/386146 to your computer and use it in GitHub Desktop.
<head>
<style>
table.container {
width: 522px;
border-spacing: 0;
border:1px solid gray;
}
.container td {
text-align: center;
padding: 0;
margin: 0;
}
.item {
background-color:red;
height:100px;
}
</style>
</head>
<body>
&darr; table with spacers
<table class="container">
<tr>
<td class="item" style="width:80px">&nbsp;</td>
<td>&nbsp;</td>
<td class="item" style="width:100px">&nbsp;</td>
<td>&nbsp;</td>
<td class="item" style="width:80px">&nbsp;</td>
<td>&nbsp;</td>
<td class="item" style="width:100px">&nbsp;</td>
<td>&nbsp;</td>
<td class="item" style="width:60px">&nbsp;</td>
</tr>
</table>
<img src="http://blog.directededge.com/wp-content/uploads/2010/04/4.png"><br/>
&uarr; example image from blog of javascript result
<p>
<p>
variable-width example
<table class="container" style="width:100%">
<tr>
<td class="item" style="width:80px">&nbsp;</td>
<td>&nbsp;</td>
<td class="item" style="width:100px">&nbsp;</td>
<td>&nbsp;</td>
<td class="item" style="width:80px">&nbsp;</td>
<td>&nbsp;</td>
<td class="item" style="width:100px">&nbsp;</td>
<td>&nbsp;</td>
<td class="item" style="width:60px">&nbsp;</td>
</tr>
</table>
</body>
@gojomo
Copy link
Author

gojomo commented May 1, 2010

A technque to help with this: http://blog.directededge.com/2010/04/30/the-curious-case-of-equidistant-boxes-a-css-fail/

Takes advantage of a browser's tendency to distribute 'excess' width evenly among TDs with unspecified widths.

Checked on Mac FF3.6, Safari 4.0.3, Chrome 5.0.342.9. That the spacer TDs have non-empty content is important for Safari/Chrome, but not FF.

May break in other compatibility modes...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment