October 15, 2001 - Out-of-Window Positioning
October 15, 2001 Out-of-Window Positioning Tips: October 2001
Yehuda Shiran, Ph.D.
|
style
object's position property can have three values: "static"
, "absolute"
, and "relative"
. One obvious difference between relative
and absolute
positioning is in the way out-of-window situation is handled. When you use absolute
positioning and your object gets placed outside the current window, a scroll bar will appear (or extend) in the proper direction, to allow its viewing. When you use relative
positioning, on the other hand, and your object gets placed outside the current window, you won't be able to see the object. Scroll bars won't be created or extended to include the object in the viewable area. Play around with the three links below and see their effect on the following layout:
This is a paragraph of text in a DIV.
This is a paragraph of text as well.
Make it static | Make it absolute | Make it relative We setoDiv.style.top
to 1700
so it won't be included in your current window. When you ask for relative
positioning, the yellow paragraph won't be visible. When you ask for absolute positioning, the yellow paragraph will be shown, by extending (or creating) the vertical scroll bar.Here is the code:
<STYLE>
.divstatic {position: static}
</STYLE>
<DIV ID=oDiv CLASS="divstatic" STYLE="background-color:yellow;width:60">
This is a paragraph of text in a DIV.</DIV>
<SCRIPT LANGUAGE="JavaScript">
<!--
oDiv.style.left = 100;
oDiv.style.top = 1700;
// -->
</SCRIPT>
<P>This is a paragraph of text as well.</P>
<A HREF="javascript:void(oDiv.style.position = 'static')">Make it static</A> |
<A HREF="javascript:void(oDiv.style.position = 'absolute')">Make it absolute</A> |
<A HREF="javascript:void(oDiv.style.position = 'relative')">Make it relative</A>