>"In practice I'm dividing dimensions of body (equal to viewport) and the
>centered element by 2, and subtract half of one from half of the
>other to get the offset needed to get the vertical mid-point of the
>element positioned in the vertical mid-point of viewport"

yup, clear...

>*if* (and only if) the viewport is tall enough to house the entire
container.
> If the viewport is too small for the element, I zero out margin-top so the
element stays inside viewport.



And here WAS my question: 
If the browsers, automatically add scroll bars to the viewport, allowing it,
with this, to grow indefinitely, then, when or how can the viewport be too
small for the element? 
I mean, each time we make the subtraction between half of the viewport with
half of the element we want to center, we will never get a negative value,
because the viewport will be always bigger then centered element, hence,
I've not understand why we have to set it to "0".

If we give a negative top margin to a element, it will get "out of range" to
the viewport. Ok.
If we force a negative top margin to go to 0, we will get the contents
visible to us on the viewport. Ok.
But I WAS not getting why we need that on a expression that seemed to never
give a negative value.

Why was I saying that the js expression "seems to never give a negative
value"? Because I have tested with this expression:

div#wrapper {
margin-top:
expression(document.documentElement.offsetHeight/2)-(parseInt(offsetHeight)/
2) +'px') ;
}

Then I have change the value of the center element to a exaggerated big
number, and then, I was surprised to see that the center element was stick
on the top, all visible, so, with margin-top 0.




But this WAS my question, not anymore, because, while I was writing this
e-mail, I've noticed that the expression above was not correct. I've
corrected the expression to this one:

div#wrapper {
        margin-top:
expression((document.documentElement.offsetHeight/2)-(parseInt(offsetHeight)
/2) +'px') ;
}

And I can now see that the element gets out of range on the top of the
viewport. So I've now understand why we need to use this first line: 
expression((document.documentElement.offsetHeight/2)-(parseInt(offsetHeight)
/2) <0 ? "0" .


Yupi!! :)


Thanks a lot for your reply, and for your time on this,

Regards,
Márcio


______________________________________________________________________
css-discuss [cs...@lists.css-discuss.org]
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/

Reply via email to