Saturday, January 14, 2012

Four different positioning method


Static positioning

HTML elements are positioned static by default. A static positioned element is always positioned according to the normal flow of the page. Static positioned elements are not affected by the top, bottom, left, and right properties.

Fixed positioning

An element with fixed position is positioned relative to the browser window. It will not move even if the window is scrolled.
Example:
p.pos_fixed
{
position: fixed;
top: 30px;
right:5px;
}

Relative Positioning

A relative positioned element is positioned relative to its normal position.
Example:
h 2.pos_left
{
position: relative;
left: -20px;
}
h 2.pos_right
{
Position: relative;
left: 20px;
}

Absolute positioning

An absolute position element is positioned relative to the first parent element that has a position other than static. If no such element is found, the containing block is <html>:
Example:
h 2
{
position: absolute;
left:100px;
top:150px;
}

Overlapping Elements

When elements are positioned outside the normal flow, they can overlap other elements. The z-index property specifies the stack order of an element. An element can have a positive or negative stack order.
Example:
img
{
position: absolute;
left:0px;
top:0px;
z-index: -1
}

No comments:

Post a Comment