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 / 11
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

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 Padding Overview
- CSS: Margins Overview
- Top CSS3 Button Tutorials
- More Top CSS3 Tutorials for Animation and Im...
- CSS Mega Menus: Adding Extra Sections
- CSS Mega Menus
- CSS3 Accordian Menu: Horizontally Display Hy...
- 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...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




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