HOLLA TECH - LEARN

Positioning Elements
 

The CSS positioning properties allow you to position an element. It can also place an element behind another, and specify what should happen when an element’s content is too big.

Elements 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 depending on the 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.

The HTML: 

<p>Paragraph with no position.</p>
<p>Paragraph with no position.</p>
<p>Paragraph with no position.</p>
<p>Paragraph with no position.</p>
<p>Paragraph with no position.</p>
<p class=“position_static”>This paragraph has a static position.</p> 

 

The CSS: 

  

p.position_static {
   position:static;
   top: 30px;
   right: 5px;
   color: red;
}

 

Result: 

Holla Tech - Learn CSS

NOTE!
Static positioned elements are not affected by the top, bottom, left, and right properties.

Fixed Positioning
 

An element with a fixed position is positioned relative to the browser window, and will not move even if the window is scrolled.
The position can be specified using one or more of the properties top, right, bottom, and left.
In the example below, the paragraph is fixed to 30px from the top and 5px from the right.

The CSS: 

p.position_fixed {
   position: fixed;
   top: 30px;
   right: 5px;
   color: red;
}

 

Result: 

Holla Tech - Learn CSS

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

Relative Positioning
 

A relative positioned element is positioned relative to its normal position.
The properties top, right, bottom, and left can be used to specify how the rendered box will be shifted.

The CSS: 

p {
   width: 350px;
   border: 1px black solid;
   position: fixed;
}
span {
   background: green;
   color:white;
  position: relative;
   top: 150px;
   left: 50px;
}

 

Result: 

Holla Tech - Learn CSS

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.

NOTE!
This value cannot be used for table cells, columns, column groups, rows, row groups, or captions.

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

Absolutely positioned elements are removed from the normal flow. The document and other elements behave like the absolutely positioned element does not exist.

NOTE!
Absolutely positioned elements can overlap other elements.

BACK NEXT

CLICK ON THE BUTTON BELOW TO GO TO THE CSS MAIN COURSE PAGE. 

CSS MAIN COURSE PAGE

 


© License: All Rights Reserved 


CONTACT HOLLA TECH – LEARN SUPPORT