In xhtml <div align=”center”> isn’t valid. Why? and how can you center something with css. All I know of is text-align and as you probably know that centers text.
Yup. Align is a 'deprecated' attribute in xhtml. Text-align actually does work in IE for non-text elements [oddly enough ;-)], but when using css try -
div#whatever{
margin:0 auto 0 auto;}
So that the left and right margins are automatically centered - depending on the parent/prior tag styles, etc.
@MstrBobAug 20.2004 — #Perhaps a sample? :rolleyes: Internet Explorer, in quirks mode, well, screws up a lot of things. the align attribute is invalid, because it's using HTML to style, when that is not the purpose of HTML. There are two methods, as stated, for centering objects in CSS. text-align:center; will center all inline elements (such as text, images, and <span></span>) and margin:auto; will center all block elments (like <p></p> and <div></div>) So you can always do:
<div style="margin:auto;">
Centered Div!
</div>
If you are having issues with it in IE, make sure you have the proper DTD. IE won't even recognize the right DTD, but if it sees one, it will run CSS "properly"
:rolleyes:
<i> </i><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
@Paul_JrAug 20.2004 — #IE doesn't support [font=courier]margin: auto;[/font] — what a surprise. :rolleyes:
To get this to work in IE, you have to apply [font=courier]text-align: center;[/font] to the [b]parent element[/b] of the element you are trying to center.
<i> </i><div id="parent"> <div id="center">This is centered!</div> </div>
This is a fairly common technique used when centering an entire layout. The [font=courier]text-align: center;[/font] is applied to the BODY, and the [font=courier]margin: 0 auto 0 auto;[/font] ect. is applied to a wrapper DIV, which houses the rest of the code.
@MstrBobAug 20.2004 — #IE in quirks mode doesn't support margin:auto; But for making my websites, I found that with a DTD, even IE will support it. At least, as of IE 6 for Windows ME.
@pawkyAug 20.2004 — #[i]Originally posted by MstrBob [/i]
[B]IE in quirks mode doesn't support margin:auto; But for making my websites, I found that with a DTD, even IE will support it. At least, as of IE 6 for Windows ME. [/B][/QUOTE]