December 16, 2009

CSS text alignment quirk

NOT OKAY:
<span style="text-align: center">
WORKS FINE:
<div style="text-align: center">

This is because span is an inline element but div is a block-level element. The text will technically be centered inside the span, but that's meaningless because the span will wrap itself tightly around its contents and will itself be placed where page flow dictates. Generally, a div will have the same width as its container, resulting in the desired effect.

No comments:

Post a Comment