CSS Positioning =============== The CSS positioning properties allow you to position an element. All CSS Positioning Properties ------------------------------- Property Description Values ---------------------------------------------------------------------------------------------------------- bottom Sets the bottom margin edge for a positioned box auto length % inherit clip Clips an absolutely positioned element shape auto inherit cursor Specifies the type of cursor to be displayed url (in JavaScript url()) auto crosshair default pointer move e-resize ne-resize nw-resize n-resize se-resize sw-resize s-resize w-resize text wait help left Sets the left margin edge for a positioned box auto length % inherit overflow Specifies what happens if content overflows an element's box auto hidden scroll visible inherit position Specifies the type of positioning for an element absolute fixed relative static inherit right Sets the right margin edge for a positioned box auto length % inherit top Sets the top margin edge for a positioned box auto length % inherit z-index Sets the stack order of an element number auto inherit 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. IE7 and IE8 support the fixed value only if a !DOCTYPE is specified. Fixed positioned elements are removed from the normal flow. The document and other elements behave like the fixed positioned element does not exist. Fixed positioned elements can overlap other elements. It will not move even if the window is scrolled: p.pos_fixed { position:fixed; top:30px; right:5px; } Relative Positioning -------------------- A relative positioned element is positioned relative to its normal position. h2.pos_left { position:relative; left:-20px; } h2.pos_right { position:relative; left:20px; } The content of relatively positioned elements can be moved and overlap other elements, but the reserved space for the element is still preserved in the normal flow. h2.pos_top { position:relative; top:-50px; } 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 : h2 { 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 (which element should be placed in front of, or behind, the others). An element with greater stack order is always in front of an element with a lower stack order. If two positioned elements overlap without a z-index specified, the element positioned last in the HTML code will be shown on top. An element can have a positive or negative stack order: img { position:absolute; left:0px; top:0px; z-index:-1; } Example 1 --------- Example 2 ---------

The overflow property specifies what to do if the content of an element exceeds the size of the element's box.

overflow:scroll

You can use the overflow property when you want to have better control of the layout. The default value is visible.

overflow:hidden

Example 3 ---------

The overflow property decides what to do if the content inside an element exceeds the given width and height properties.

You can use the overflow property when you want to have better control of the layout. Try to change the overflow property to: visible, hidden, scroll, or inherit and see what happens. The default value is visible.
Example 4 ---------

Mouse over the words to change the cursor.

auto
crosshair
default
e-resize
help
move
n-resize
ne-resize
nw-resize
pointer
progress
s-resize
se-resize
sw-resize
text
w-resize
wait