The Wayback Machine - https://web.archive.org/web/20090122055211/http://www.webreference.com:80/html/tutorial18/2.html


spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / html / tutorials / 18 / 2

index1234

Tutorial 18: CSS Positioning, Part I

Developer News
Marketecetera Aims to Drive Open Source Trading
Vista Support Upped in Red Hat Ent. Linux
Ruby on Rails Gets New Support in the Cloud

Relative positioning

Relative positioning is similar to static positioning, except that relatively positioned boxes can be moved around from where they normally should be. A relatively positioned box appears to be part of the normal flow as far as everyone else is concerned; it takes up space and moves its neighbours away from it to make space for itself, just like all statically positioned boxes, but it is displayed shifted in one or more directions. Here's an example:

P#two {
 position: relative;
 top: 1em;
 left: 1em;
}
<P ID="one">This is box one.</P>
<P ID="two">This is box two.</P>
<P ID="three">This is box three.</P>

The second paragraph is displayed 1em down and 1em to the right of where it should be, but otherwise nothing changes with the layout of the page. (If you're a bit confused, remember that the top and left properties specify the offset from the top edge and the left edge of where the box starts off, so the actual displacement is to the right and down). Relative positioning is a bit like absolute positioning with respect to the element itself. The important difference is, however, that with absolute positioning, the box is completely removed from the rest of the document, and other boxes are placed as if the element never existed; with relative positioning, other boxes behave as if the element was always there.

As you might have guessed, relative positioning is sort of useless most of the time. It is rarely needed to take a box and shove it in some direction just for the fun of it. However, relatively positioned boxes have a very useful property: Just like with absolutely positioned boxes, any absolutely positioned children of theirs will use them as a reference. Also, the top, bottom, left and right properties can all be left at their default value of 0. So, by taking an element, setting the position property to relative and leaving the offsets at zero, the box will be displayed at its original position, still take up space in the document flow, but also define a new set of co-ordinates for its absolutely positioned children.

index1234

http://www.internet.com/

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Copyright 2008 Jupitermedia Corporation All Rights Reserved.

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

webref The latest from WebReference.com Browse >
Marketing 2.0: Gaming, Widgets, Blogging, RSS, Podcasts and More · How to Use the 'AddThis' Social Bookmarking Service · The New Vessels: The New Language of Marketing 2.0
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

Legal Notices.

URL: http://www.webreference.com/html/tutorial18/2.html

Produced by Stephanos Piperoglou
Created: February 15, 2000
Revised: February 16, 2000

Morty Proxy This is a proxified and sanitized view of the page, visit original site.