There seem to be some general misunderstandings in this thread that I think need clearing up.

Originally Posted by
themind
#container {
position: relative;
margin: 0 auto;
}
That obviously doesn't center anything in IE [...]
As it is, that shouldn't centre the container element in any user agent. The reason requires looking at the algorithm used for calculating block-level element widths:
If 'left' or 'right' are given as 'auto', their computed value is 0. The following constraints must hold between the other properties:
'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containing block
(If the border style is 'none', use '0' as the border width.) [...]
If there is exactly one value specified as 'auto', its computed value follows from the equality. [ed: Doesn't apply here as 'width', 'margin-left' and 'margin-right' are all 'auto'.]
If 'width' is set to 'auto', any other 'auto' values become '0' and 'width' follows
from the resulting equality. [ed: This is the clincher! The algorithm stops here in this case as 'margin-left' and 'margin-right' are now both '0', so the step below doesn't apply.]
If both 'margin-left' and 'margin-right' are 'auto', their computed values are
equal. [ed: This is the property we want to eventually use.]
If you followed the above, it should be clear that in order to centre a block-level element, you need to give that element an explicit width other than auto, otherwise it will just default to taking up as much width as it possibly can.
You may also want to use separate properties for the left and right margins as IE/Mac doesn't apply the shorthand properly:
Code:
margin-left: auto;
margin-right: auto;
I could change all my other divs to be positioned absolutely, but then it gets real funky and starts to look different in every single browser.
It will also be completely rigid, forcing a horizontal scrollbar (the worst kind) in browsers that have a viewport that is smaller than you'd like. That said, if you're implementing a fixed-width design (generally inappropriate on the Web), that will probably happen anyway.

Originally Posted by
jscheuer1
Because IE does not respect auto in margin declarations [...]
IE6 and IE/Mac does in 'Standards' mode, but not in earlier versions or 'Quirks' mode. This can be worked around using a browser bug where the text-align property applies to block-level elements, but that won't do much unless the problem I mentioned above is addressed.
IE thinks there is a css element, *html, that sits atop everything else.
First of all, the selector is '* html' (that is, [asterisk] [space] html, which is what you originally posted, John). What this would match is any html element that is a descendant of some other another element.
The problem here is that the html element is the root element in any HTML document (which is why it appears in the DOCTYPE declaration), so this should never apply. True to IE though, bad programming makes it believe otherwise. Still, this is useful in cases where you need to apply different rules to IE to correct even more serious bugs.
Mike
Bookmarks