Style Sheets
  Home arrow Style Sheets arrow Page 3 - Using Relative Positioning For Consistent ...
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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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

Using Relative Positioning For Consistent Layout
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 18
    2005-06-23

    Table of Contents:
  • Using Relative Positioning For Consistent Layout
  • Relative Positioning Explained
  • A Basic Web Page
  • Now that’s Style!

  • 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


    Using Relative Positioning For Consistent Layout - A Basic Web Page


    (Page 3 of 4 )

    Let’s use the example of a very basic Web page, with four primary elements:

    • a logo

    • a navigation box

    • a main content area

    • a footer

    Here’s the XHTML code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

      <meta content="text/html; charset=ISO-8859-1"

     http-equiv="content-type" />

      <title>A Basic Web Page</title>

      <link rel="stylesheet" href="styles.css" type="text/css" />

    </head>

    <body>

    <div id="all" align="center">

    <div id="logo"><a href="index.htm"><img

     style="border: 0px solid ; width: 300px; height: 50px;"

     src="images/logo.png" /></a></div>

    <div id="nav">

    <a href="page1.htm">page 1</a><br />

    <a href="page2.htm">page 2</a><br />

    <a href="page3.htm">page 3</a><br />

    <a href="page4.htm">page 4</a><br />

    <a href="page5.htm">page 5</a>

    </div>

    <div id="main_content">

    <h1>My Page</h1>

    <p>A paragraph with some content.</p>

    <p>This is where all the main content of each page will be located, as is indicated by the id of the containing div.</p>

    </div>

    <div id="footer">

    &copy; 2005 | <a href="mailto:">Contact me</a>

    </div>

    </div>

    </body>

    </html>

    As you can see in the code, all the body contents and elements are contained in one all-encompassing div, unambiguously named "all." I use this method for the sole purpose of centering everything, and modifying positions relative to the center of the screen, no matter what the resolution. This raw XHTML will produce the following results:


    Now let’s make things pretty with some relative positioning!

    More Style Sheets Articles
    More By Justin Cook


       · I appreciate what you tried to achieve here, but if you want to write this kind of...
       · I too appreciate what you've tried to achieve, that is shameless self...
       · [quote]I too appreciate what you've tried to achieve, that is shameless self...
       · If you really are a writer here, I'm quite surprised that you would post these...
       · I think there's another way of design web pages that use absolute positioning (thus...
       · Absolute positioning means absolute to the page. I don't believe that method would...
       · Great explanation of CSS relative positioning. You isolate the problem at hand and...
       · "But it's downright frustrating to realize that the positioning you've chosen...
       · Clear and simple, they way few in the industry can keep things.You saved my...
       · I'm not sure what this author was trying to achieve. This is not a flexible layout,...
     

    STYLE SHEETS ARTICLES

    - Adding Semantic Meaning to Styled Code Block...
    - Styling Code blocks with CSS: Using pre HTML...
    - Building Rounded Corners with CSS3
    - Finishing a Casual Navigation Bar with CSS S...
    - Defining a Navigation Bar`s Hover State with...
    - Styling a Blog`s Links Bar with CSS Sprites
    - Creating an Artistic Blog Header with CSS Sp...
    - Defining the Active State of Menu Sections f...
    - Styling the Hover State of a CSS Sprite-Base...
    - Building CSS Sprite-Based Navigation Bars
    - Creating Framed Pictures with CSS
    - Using a CSS Shading Effect to Decorate Images
    - Decorating Images with CSS
    - Finishing a Drop-Down Menu with the Hover CS...
    - Creating a Drop-Down Menu with the Hover CSS...







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek