Academic Tutorials

English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting

CSS 2.0
CSS 2.0 Introduction
CSS 2.0 Attaching Style
CSS 2.0 Applying Style
CSS 2.0 Key Concepts
CSS 2.0 Color Contents
CSS 2.0 Fonts Contents
CSS 2.0 Text
CSS 2.0 Lists
CSS 2.0 the box model
CSS 2.0 Advanced concepts
CSS 2.0 Positioning
CSS 2.0 Boxes
CSS 2.0 Generated content
CSS 2.0 Dynamic effects
CSS 2.0 Tables
CSS 2.0 Paged media
CSS 2.0 Font Face
CSS 2.0 Aural Style Sheets
CSS 2.0 Language styles

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
Apple Script
PL/SQL Tutorial
SQL Server
.NET (dotnet)
.Net Mobile
C# : C Sharp
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Assembly Language
Forth Programming
Lisp Programming
Data Warehousing
CGI Programming
Emacs Tutorial
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Operating System
Software Testing
SAP Module
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Financial Accounting
Managerial Accounting
Network Sites

CSS 2.0 Properties - Positioning

Previoushome Next

CSS2 Properties - Positioning


Positioning schemes

There are 3 positioning schemes in CSS 2. Firstly, normal flow, which includes block elements, inline elements, list-items, etc., and the positioning of these elements relative to their ordinary positions; secondly, floats, and thirdly, absolute positioning, which positions content relative to a fixed point.


The float property alters the normal behavior of an element. For example, it can be used to create a drop cap effect.

Possible values for the float property are left, right and none, where none is the initial value. The effect of setting float is similar to making the element part of the specified margin - float: left will cause it to be part of the left margin. Subsequent non-floated block elements to the float treat it as though it wasn't there, and thus overlapping results. However, inline content (such as text inside the float) will wrap around the float.

Floated block elements do, however, take the position of floats into account. E.g.:

<div style="height: 100px; width: 100px; border: solid; float; left">
<div style="height: 100px; width: 100px; border: solid; float; left">

That would be rendered thus (except without the space between the floats):

+---+ +---+
|   | |   |
|   | |   |
+---+ +---+

Here's an example showing how inline content flows around floats:

  <SPAN style="float: left; font-size: 72px; line-height: 72px; width: 50px">T</SPAN>he cat sat on the mat<BR> again <BR>once more. </P>
  New paragraph flows round it and continues after it.

---------------he cat sat on the mat
        |      again
        |      once more
        |      New paragraph flows round it
and continues after it.

Note how the top of the floating T is aligned with the top of the line, and how the next block element continues to wrap around it.

SPAN.dropcap {float: left;
font-size: 48px; width: 30px; line-height: 48px}

The above example can be used to create a drop cap.

Float applies to all elements and is not inherited.

All browsers support float buggily, and IE 3 not at all.


The clear property prevents an element from flowing round a floating element

Possible values for clear are left (preventing the element from starting (i.e., a cleared element can contain floating elements, but it will not flow round floating ones) around a left floated element), right (preventing the element from starting around a right floated element), both (preventing an element from starting around a floated element), or none (allowing floating on both sides) - the initial value.

To clear the element, the element is moved down below the float.

Clear applies only to block elements and is not inherited.

Note that clear does not prevent floating inside the element - if <P style="clear: left">Some text<IMG style="float: left"> then the image would float normally, but if <IMG style="float: left"><P style="clear: left">Some text</P>, then P would start below the image - clear only relates to whether an element can start in a given position.

IE 3 does not support clear, and all other browsers have problems with it, so test carefully.


In CSS positioning, an element's position is specified relative to a reference point.

Generated content may not be positioned. Positioning properties are not inherited.

In order to specify the position of elements, four properties are used. These properties are top, left, right and bottom.

To specify the type of positioning that is desired, the position property is used. This property takes four values: static, absolute, fixed and relative.

Position: relative specifies that the element will be relatively positioned, position: absolute that it will be absolutely positioned, position: static that the element will flow normally, and position: fixed that the element will be fixed with respect to the document window or viewport.

It is important to note that positioned elements cannot be floated, and therefore that position declarations other than static will override float declarations.

In addition, positioned elements do not collapse margins.

Absolute positioning

In absolute positioning, the position of an element is specified relative to edges of a box known as a containing block.

In addition, unlike in static positioning, boxes are removed from normal flow entirely, and as such, they do not affect the position of other elements. Ordinary absolute positioning is of little use except for scripting purposes, where the fact that it does not cause reflow of content makes it ideal.

Fixed positioning allows you to create such effects as frame-style navigation or adbars in a fixed place.

Note that all absolutely positioned elements are block-level elements, and therefore display: inline declarations have no effect.

Relative positioning

In relative positioning, elements are moved relative to their normal position, but with subsequent elements treating them as though they were in their original position.

Specifying the offsets of elements

There are four properties that can be used to specify the offsets of positioned elements:

  1. top
  2. bottom
  3. left
  4. right

The values for these properties can be specified as a length, % (relative to the height of the containing block, in the case of top and bottom, and to the width in the case of left and right). Alternatively auto can be specified (initial value). These properties are not inherited and apply only to positioned elements.

If a % is specified for or top bottom, but the containing block's height is unknown (i.e., it is not explicitly specified (using the height property) or fixed (as the height of the viewport is)), it is ignored and treated is auto.

For example, top: 100px specifies an offset of 100 pixels.

The meaning of auto

The auto value places the element in the position it would normally be. Thus for relatively positioend elements 'auto' will be treated as 0. For absolutely positioned elements, it is interpreted as the value necessary to place the element in the position that it would be in but for the absolute positioning.

Relative positioning

Top specifies how much the element is moved down from its normal position. For example, position: relative; top: 10px moves the element 10 pixels down from its normal position, and position: relative; top: -10px moves the element 10 pixels up. Left specifies how much the element is moved the element is moved to the right of the normal position. For example, left: 10px moves the element 10 pixels to the right, and left: -10px, 10 pixels to the left. Right specifies how much the element is moved to the left of its normal position. For example, right: 10px moves the element 10 pixels left, and right: -10px moves the element 10 pixels right. Bottom specifies how much the element is moved above its the normal position. For example, bottom: 10px moves the element 10 pixels up, and bottom: -10px, 10 pixels down.

Absolute (including fixed) positioning

Top specifies the offset of the top margin edge below the top edge of the element's containing block, and left the offset to the right of the left edge of the element's containing block. Thus top: 50px places the top margin edge of an element 50 pixels below the top edge of the element's containing block.

Bottom refers to the offset of the bottom margin edge below the bottom edge of the box's containing block, and right the offset of the right margin edge to the left of the right edge of the element's containing block.

Containing blocks and absolutely positioned elements

This containing block, although it sounds rather complicated, is actually quite a simple concept. Consider the following box:

|                            |
|                            |
|                            |
|                            |
|                            |
|                            |
|                            |
|                            |
|                            |
|                            |
|                            |

If that is a containing block, you can then use the edges of that block to specify the position of an element.

So if you specify <DIV style="position: absolute; top: 100px; left: 100px; border: solid">Some content</DIV>, this will be the result:

|                            |
|                            |
|                            |
|              +------------+|
|              |Some content||
|              +------------+|
|                            |
|                            |
|                            |
|                            |
|                            |

As you can see, the top: 100px and left: 100px have placed the top edge of the element 100 pixels below the top edge of the containing block, and the left edge 100 pixels to the right of the left edge of the containing block.

What is the containing block?

For fixed positioning (a subset of absolute positioning) the containing block is always the viewport (i.e., the 'window' in which content is rendered in a browser). This means that the element is 'fixed' when you scroll the document. This means that the declaration top: 50% means the top margin edge of the element should be halfway down the viewport.

For ordinary absolutely positioned elements, the containing block is a more complex affair. The containing block is the nearest ancestor of the element with a position other than static.

If that ancestor is block-level, offsets are relative to the padding edges of that element; if, however, it is inline (therefore relatively positioned, since all absolutely positioned elements are block-level), offsets are relative to the content edges of the first box generated by that element.

If there is no such element, the content edge of <BODY> is used (in XML, the root element will be used).


CSS positioning is supported by Netscape and IE 4 and 5.

Netscape does not color in the background properly on absolutely positioned elements unless the Netscape-specific layer-background-color is set to the same value as background-color.

Positioning examples

Fixed example

#adbar {postion: fixed;
height: 20%}
#menu {position: fixed;
width: 20%;
top: 20%}
#main {position: fixed;
top: 20%;
left: 20%}

<DIV id="adbar"> . . .</DIV>
<DIV id="menu"> . . .</DIV>
<DIV id="main"> . . .</DIV>

|  adbar                   |
|                          |
| menu  |                  |
|       | main             |
|       |                  |
|       |                  |
|       |                  |
|       |                  |
|       |                  |

Relative example

Some content, with <SPAN style="position: relative; top: 100px">this that will be relatively positioned 100 pixels down</SPAN>.

Absolute example

<P style="position: absolute; top: 100px">
An element that will have its top margin edge 100 pixels below the top edge of the containing block (typically the top edge of BODY).

Be the first one to comment on this page.

  CSS 2.0 eBooks
More Links » »
 CSS 2.0 FAQs
More Links » »
 CSS 2.0 Interview Questions
More Links » »
 CSS 2.0 Articles

No CSS 2.0 Articles could be found as of now.

 CSS 2.0 News

No News on CSS 2.0 could be found as of now.

 CSS 2.0 Jobs

No CSS 2.0 Articles could be found as of now.

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: CSS2 Properties - Positioning, CSS2, css2, CSS2 tutorial, CSS2 tutorial pdf, history of CSS2, Custamizing Style Sheet, learn CSS2

HTML Quizzes
CSS Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
XML Quizzes
XML Quiz
XSL Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright ? 2008. Academic All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World | Important Websites
Copyright ? 2003-2024 Vyom Technosoft Pvt. Ltd., All Rights Reserved.