CSS

adplus-dvertising
Working with positioning in CSS
Previous Home Next

Positioning

CSS positioning properties will help you to position an element to place an element behind another, and specify what should happen when an element's content is too big. It can be positioned using the top, bottom, left, and right properties. However, these properties will not work unless the position property is set first. They also work differently depends on the positioning method. Positioning methods are given below-

  • Static Positioning
  • Fixed Positioning
  • Relative positioned
  • Absolute position

Static Positioning

HTML elements are positioned static by default. A static positioned element is always positioned according to the normal flow of the page. It is 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:

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;
}

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>.

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).

img
{
position:absolute;
left:0px;
top:0px;
z-index:-1
}
Previous Home Next