The Wayback Machine - https://web.archive.org/web/20090429214129/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
Facebook Opens Its 'Stream' to New Apps
Learning From Mozilla Security
Is Microsoft Readying 'XP Mode' for Windows 7?

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.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info
Copyright 2009 WebMediaBrands Inc. All Rights Reserved.

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

webref The latest from WebReference.com Browse >
CMS: A Look Back and The Way Ahead · Introducing jQuery · Debugging JavaScript: Understanding JavaScript Error Messages
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Review: Asus Eee Top PC ET1602 · Intel to Host Live Nehalem Q&A; · How to Convert a Physical PC into a Virtual One

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.