> If I instead set a height on the same div, and then set margin: auto 0; it
> does not center horizontally.
I'm going to assume that you really meant vertically.
> Why? why why why?
Because the definition of "auto" states that if auto is the same for
margin-left and margin-right, then they will be equal. It doesn't specify the
same rule for margin-top and margin-bottom, so auto really ends up just acting
as the default.
> Would the block center vertically if the containing block had a declared
> height, or does that not matter either?
It would not.
> Thoughts?
If you're in a position be able to specify height on both the block and it's
container, then this is pretty easy to accomplish. If you can't do that, then
the only ways to do it are resorting to tables or javascript.
<div class="middling parent">
<div class="middling child"></div>
</div>
.middling.parent {
position: relative; /* create a position context */
height: 10em; /* need to specify a height */
}
.middling.child {
position: absolute;
top: 50%; /* puts top in the middle of parent - requires that the parent has
a height */
height: 3em; /* give the child height */
margin-top: -1.5em; /* negative top margin of half child height to move it
back up to centered */
}
---Tim
______________________________________________________________________
css-discuss [[email protected]]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
List policies -- http://css-discuss.org/policies.html
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/