Home arrow Style Sheets arrow Page 2 - Using Relative Positioning For Consistent Layout
STYLE SHEETS

Using Relative Positioning For Consistent Layout


Converting a site to Web standards can be quite a struggle. It’s difficult enough to achieve a satisfying layout with positioning, floating, and all that. But it’s downright frustrating to realize that the positioning you’ve chosen doesn’t render consistently in different resolutions, or even multiple browsers in the same resolution! Well, take heart; this article will explain why relative positioning is a trustworthy friend in this case!

Author Info:
By: Justin Cook
Rating: 4 stars4 stars4 stars4 stars4 stars / 18
June 23, 2005
TABLE OF CONTENTS:
  1. · Using Relative Positioning For Consistent Layout
  2. · Relative Positioning Explained
  3. · A Basic Web Page
  4. · Now that’s Style!

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using Relative Positioning For Consistent Layout - Relative Positioning Explained
(Page 2 of 4 )

To explain it simply: each block-level element on a web page takes up a chunk of space. That chunk of space receives a default location in the flow of the page at runtime, as it is loaded in order with other elements. By defining the element’s position as relative (through CSS) and modifying the respective properties, you move the element from where it should be located. This will also have an effect on all other relatively positioned elements.

Here’s an example:

<div style="width: 100px; height: 100px; background-color: #CCC; position: relative; top: 15px; left: 15px; ">relativity is great, this is no theory!</div>

So this div (layer) has been moved 15 pixels away from its default top and left position. This means it will move 15 pixels down and 15 pixels to the right. If this moves the element into the default position or space of another element, one of two things will happen:

  1. If the other element’s position is absolute or undefined, you will get overlap. This usually isn’t pretty. You may want to achieve this effect sometime with alpha-indexed PNGs, but you’ll still want to control the overlap by defining the relative positioning of each element, instead of leaving it up to the browser’s rendering judgment.

  2. If the other element’s position is also relative, the other element will also move, relative to the position of the first. This is the way we can achieve a very fluid, consistent layout, and the methodology discussed in this article.


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials