Style Sheets
  Home arrow Style Sheets arrow Page 5 - Introduction to CSS Positioning Properties...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Introduction to CSS Positioning Properties Part 1
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2005-02-21

    Table of Contents:
  • Introduction to CSS Positioning Properties Part 1
  • Basic definitions
  • Inline and block boxes
  • CSS 2 Positioning Schemes
  • The "position" property
  • The "display" property

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Introduction to CSS Positioning Properties Part 1 - The "position" property


    (Page 5 of 6 )

    As its name implies, this property is used to set the type of position applicable to the selected element. The following values can be defined:

    position: static; (default behavior for all elements)

    position: relative; (uses relative positioning for this element using the top, right, bottom and left properties)

    position: absolute; (uses absolute positioning for this element using the top, right, bottom and left properties)

    position:fixed; (uses fixed positioning for this element using the top, right, bottom and left properties)

    As previously mentioned, for most of positioning schemas, it’s necessary to specify "top," "left," "right" and "bottom" properties. Let’s see each one of them in detail.

    The "top," "right," "bottom" and "left" properties

    As we can see, to properly implement CCS2 positioning schemas, we need to define "top," "left," "right" and "bottom" properties. However, specifing both "top" and "bottom," or "left" and "right" properties simultaneously, will render an undesirable visual effect, and not achieve what we really want from them. Generally, we’ll end up utilizing the top and left properties to efficiently position an element in the desired location.

    We can use the following values for these properties:

    Fixed Length: It’s possible to specify a fixed value expressed in pixels (px), points(pt), inches(in), centimeters (cm), millimeters (mm), ems (em), or picas (pc). For instance, we can define several examples, such as this:

    #content {

         position: absolute;

         width: 500px;

         left: 300px;

         top: 150px;

    }

    And this:

    #content {

         position: absolute;

         width: 500px;

         right: 200px;

         bottom: 150px;

    }

    However, the last example is somewhat unusual, and would not normally be used. For most cases, specifying the left and top properties is the safest way to position an element in a Web document.

    Also, percentage values may be set. It’s possible to assign a percentage value, generally well suited for liquid designs, where the element’s size gets expanded or collapsed according to different screen resolutions:

    /P>

    #content {

         position: absolute;

         width: 68%;

         left: 30%;

         top: 20%;

    }

    Or, using the right and bottom properties:

    #content {

         position: absolute;

         width: 68%;

         right: 20%;

         bottom: 30%;

    }

    In our two last examples, we specified a percentage value for each element. In the first case, the content selector will be positioned at 30 percent of the parent element’s width and 20 percent of its height. The second case shows that the element will be positioned at 20 percent of the parent’s width and 30 percent of its height. Once again, this approach is rarely used. Keep in mind that "top" and "left" properties are perfectly suitable for all of the situations.

    That’s our quick guide to CSS2 position schemes in Web documents. Certainly, concerning each CSS property, browser support may vary considerably, particularly when referring to old browsers.

    It’s time to have a look to another CSS2 visual property: the "display" property.

    More Style Sheets Articles
    More By Alejandro Gervasio


       · Here's a quick guideline for commom CSS display properties. I think it's useful...
       · For the sake of accuracy, there's a /p> missing tag in the article.
     

    STYLE SHEETS ARTICLES

    - Creating Three-Column Web Page Layous with N...
    - Swapping Column Positions in Web Page Layout...
    - Creating Web Page Layouts with Negative Marg...
    - Creating Gradients for Individual Containers...
    - Creating Gradients for Web Page Headers with...
    - SEO Scrolling Frames Problem Solved
    - Building Cross-Browser Background Effects wi...
    - CSS: Pseudo
    - Using PNG Images to Build Background Effects
    - CSS: Continuing the Clarification of CSS Cla...
    - CSS: Top Secret Classification
    - CSS: Dimensions
    - CSS: Margins and Padding
    - CSS: Crossing the Border
    - CSS: Text, Fonts, and Tables







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway