Home arrow Style Sheets arrow Page 5 - Introduction to CSS Positioning Properties Part 1
STYLE SHEETS

Introduction to CSS Positioning Properties Part 1


Web designers gained a great deal from the CSS2 specification, especially when it comes to increased flexibility to position HTML elements exactly where they want them within Web pages. Keep reading to learn more.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 8
February 21, 2005
TABLE OF CONTENTS:
  1. · Introduction to CSS Positioning Properties Part 1
  2. · Basic definitions
  3. · Inline and block boxes
  4. · CSS 2 Positioning Schemes
  5. · The "position" property
  6. · The "display" property

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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.


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 5 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials