Home HTML/CSS CSS: Position Property - Absolute and Fixed
Author:

I have received some questions from readers asking about Position property in CSS. Today, I will introduce to you the Position attribute of CSS property. You will learn how to define and use it properly.

The CSS positioning properties allow you to position an element. You can place an element anywhere you want on the web page.

Absolute Attribute:

Absolute position is based in 4 locations: top, right, bottom, left, along with units such as px, cm and em,%.  This is used for alignment by the composition containing it. You can actually just rely on one of the following pairs of position to set a location of an element on the page:

  • top-left
  • top-right
  • bottom-left
  • bottom-right

Sample:

HTML code:
css_01

CSS:
css_02

First: assign attribute position: relative to the #container element.

Result:
css_03

Fixed Attribute:

An element with a fixed attribute is positioned relative to the browser window. It will not move even if the window is scrolled.

Note: IE7 and IE8 support the fixed value only if a !DOCTYPE is specified.

Example:

HTML code:
css_05

CSS:
css_04

Did you like this tip



Comments (0)
Write comment
Your Contact Details:
Comment:
Security
Please input the anti-spam code that you can read in the image.

"