This is an old revision of the document!
A common request is the ability to center blocks. CSS has some capabilities for this, however they are very limited, especially in the vertical direction.
Horizontal centering can be accomplished in most cases by using margin: 0 auto
: setting both the left and right margins to auto
causes them to be equal. There are some limitations however.
Vertical centering currently cannot be done in CSS except for
The main request is to vertically center the contents of a box, as can be done with vertical-align: middle
on table cells. A secondary request is the ability to vertically-justify content within its containing block.
Ian and Tantek have a position:center proposal that does both horizontal and vertical centering. It uses the background-position method of calculating positions and applies it to the absolute positioning model. It gives a lot of flexibility in placing boxes relative to their containing block, but is a form of absolute positioning and can't be used for in-flow boxes.