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.
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.
Markus started a discussion about an alignment property to standardize on syntax to implement <CENTER>
. The property affects the alignment of boxes, not of text within the boxes, and it inherits. Unsettled details include:
left
| center
| right
left
| center
| right
| start
| end
top
and bottom
values that apply in vertical layout. (Such a set should allow specifying e.g. both top
and left
at the same time, where one takes effect in vertical text and the other in horizontal text.)alignment
is the working name. An alternative would be horizontal-align
, to be consistent with vertical-align
.alignment: left
vs. alignment: true left
). In this case both alignment behaviors are possible, and the default behavior emphasizes accessibility.alignment
trumps auto
margins: auto
margins are set to zero and then the box is aligned as specified.alignment
defers to auto
margins: it only affects blocks without auto
side margins. (Note that the default margin is '0'.)auto
as appropriate to effect specified alignmentVertical 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.