CSS Tricks: Center Table

Using auto to split up the remaining space.

CSS

In this section, I will attempt to document and demonstrate how to overcome some of the little problems that many developers encounter while transitioning from transitional to strict doctypes.

How to Center a Table with CSS

Someone seems to have forgotten that blocks need to be centered. If text-align:center is so good, why did they forget to make a block-align:center? But they did! This one’s easy—once you realize the power of that little word, auto. Applied to opposing margins, auto means, “split and use up the remaining available space.” The result: block centering, even in a fluid layout.

The following CSS means “collapse the table to it’s contents and center it.”

table.ct {
 width:auto; margin:0 auto 0 auto; }
Absmid

A CSS-centered, fluid table, with absmiddle-type text
alignment—and no proprietary deprecated markup in sight.

“If both margin-left and margin-right are auto, their used values are equal. This horizontally centers the element with respect to the edges of the containing block.” —CSS2.1, 10.3.3 ¶7

— KV5R is disabled. Please help. —

Valid HTML 5 Valid CSS WCAG 1 conformance Handmade with Ultra Edit Studio Xara Xtreme