Previous Message
Next Message

RE: [css-d] Cant get a <div> to center!

Sent by Mike Marco on 22 June 2003 11:11


Kevin W wrote:
>> To center your DIV, add "align-left: auto; align-right: auto" to
>> "div.galnav".  Those, in addition to the fact that you've specified a
>> width, should center the DIV.  Let me know if it doesn't work...
>
> I think you mean "margin-left" and "margin-right" instead of align...

Or you could just write a combined rule:

margin : auto;

(Unless, of course, you want to explicitly specify top and bottom margins as
well.)

Note that in IE5/Win (both 5.0 and 5.5), automatic margins are not handled
properly. However, IE5/Win seems to have no problem centering block-level
elements like inline elements. In other words, adding a text-align : center
property to BODY will center any block-level element within the document
body.

BODY {
	text-align : center;
	...
}

Of course, because text-align is inherited by child elements, you'd have to
put text-align : left in the DIV's property. So the CSS definition for
DIV.galnav would look something like this:

DIV.galnav {
	text-align : left;
	...
}

(The child elements of DIV.galnav will therefore inherit text-align : left.)

My personal site (http://redgreenblue.org/) shows this in action. My CSS is
inline with my XHTML, so it should be easy to spot.

HTH,
-MikeM


______________________________________________________________________
css-discuss [EMAIL-REMOVED]]
http://www.css-discuss.org/mailman/listinfo/css-d
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/
Previous Message
Next Message

Message thread: