[thelist] Horizontal element alignment with CSS1

MRC webmaster at equilon-mrc.com
Fri Nov 9 12:56:39 CST 2001


> Can anybody enlighten me on how to effectively replace 'align=center' (in
> DIVs, H1s, TDs, etc.) with a CSS1 control? I've scoured all the references
> have but could only find a 'text-align' property, which only seems to
> to text within an element rather than the element itself. This is
> me, because there is a 'vertical-align' property which DOES affect entire
> elements.

    Well, text-align: center does replace align="center" in the specific
instances that you site (divs, hxs, tds). It's intended to center inline
content within a block element.
    If you want to center a block element itself on the page, take a step
back first: typically block elements span the entire width of their
container, so centering them within that container may not make sense.
Tables are not quite the same beastie, since by default their width is only
as wide as necessary to contain their content.
    If, however, you explicitly set the width of a block element (including
a table) to something less than 100%, you need to set "margin: auto" to
cause your block elements to center. Keep in mind that this only works in IE
6 in standards-compliance mode and Netscape 6 (not sure about Opera

James Aylard

More information about the thelist mailing list