[thelist] Horizontal element alignment with CSS1

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


Paul,

> 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
I
> have but could only find a 'text-align' property, which only seems to
apply
> to text within an element rather than the element itself. This is
confusing
> 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
offhand).

James Aylard





More information about the thelist mailing list