spacer
Yehuda Shiran October 15, 2001
Out-of-Window Positioning
Tips: October 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

The 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 set oDiv.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>

People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint