The Wayback Machine - https://web.archive.org/web/20080704134240/http://www.webreference.com/html/tutorial18/3.html


spacer

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

home / experts / html / tutorials / 18 / 3

index1234

Tutorial 18: CSS Positioning, Part I

 
Search
 


Developer News
Sir Tim Talks Up Linked Open Data Movement
From L.A. to Vegas With 100GbE
Salesforce Rolls Out Big Summer '08 Update

Putting it all together

The most common use of absolute positioning is to create a columnar layout for your pages. Say, for instance, that you wish to get a block of text to appear to the right of your main text. You have to have a document that looks like this:

<P>This is normal text.</P>

<DIV ID="columns">

<P>This is some text. This is 
some text. This is some text. This is some text. 
This is some text. This is some text. This is some
text. This is some text. This is some text. This 
is some text. This is some text. This is some text. 
This is some text. This is some text. This is some 
text. This is some text. This is some text. This is
some text. This is some text. This is some text. 
This is some text. This is some text. This is some 
text. This is some text. This is some text. This is 
some text. This is some text. This is some text. 
This is some text. This is some text. This is some 
text. This is some text. This is some text. </P>

<DIV ID="right">

 <P>This text will appear to the right 
   of the rest of the text.</P>

</DIV>

<P>This is some text. This is 
some text. This is some text. This is some text. 
This is some text. This is some text. This is some
text. This is some text. This is some text. This 
is some text. This is some text. This is some text. 
This is some text. This is some text. This is some 
text. This is some text. This is some text. This is
some text. This is some text. This is some text. 
This is some text. This is some text. This is some 
text. This is some text. This is some text. This is 
some text. This is some text. This is some text. 
This is some text. This is some text. This is some 
text. This is some text. This is some text. </P>

</DIV>

<P>This is more normal text.</P>

To achieve the columnar layout, we will apply the following style sheet to the document:

#columns {
 position: relative;
 top: 0;
 right: 0;
 padding-right: 10em;
}
#right {
 position: absolute;
 top: 0;
 right: 0;
 width: 9em;
}

Let's go through these rules one by one: First, we set the positioning of the container (the DIV element with ID of columns) to relative. This will make our positioned box (the P element with ID of right) use the container as a reference for its position. We also give it a right padding of 10 ems to make room for our box. Notice that we use padding, not margin; since, as you remember, the width of an element is inside its margins, and contains the padding. If we set the right margin to 10em, then 10 ems of margin will be to the right of the main text and our positioned box.

Now that we've made space for our box, we can place it. We set the position property to absolute, placing it at the top right edge of its container, and set its width to 9 ems. The end result should look like this:

A box positioned to the right of the main document flow.
A box positioned to the right of the main document flow.

index1234

http://www.internet.com/



JupiterOnlineMedia

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

Solutions
Whitepapers and eBooks
IBM eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
webref The latest from WebReference.com Browse >
Book Review: Head First JavaScript · Web Hosting Control Panels · Use Your Blog for Fast Search Engine Rankings
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
NetApp's Virtual Storage Strategy Crystallizes · F/MC Watch: A Cisco-Centric Approach · Olympic Time Trials Use Wi-Fi Mesh

Legal Notices.

URL: http://www.webreference.com/html/tutorial18/3.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.