Raj Kumar
Computer Science And Engineering

Explain Positioning elements in CSS

Web Technology and its Applications

Explanation

1209    0

The position property specifies the type of positioning method used for an element.

There are five different position values:

  1. Fixed
  2. Static
  3. Relative
  4. Absolute
  5. Sticky
  • Static :- 

    HTML elements are positioned static by default.

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

    An element with position: static; is not positioned in any special way; it is always positioned according to the normal flow of the page:

    This <div> element has position: static;

    Here is the CSS that is used:

    div.static {
      position: static;
      border: 3px solid #73AD21;
    }
  • position: relative;

    An element with position: relative; is positioned relative to its normal position.

    Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position.

  • position: fixed;

    It is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used to position the element.

  • position: absolute;

    position: absolute; is positioned relative to the nearest positioned ancestor. However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.

  • position: sticky;

    position: sticky;  it's positioned based on the user's scroll position.

    A sticky element toggles between relative and fixed, depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place



Share:   
   Raj Kumar
Computer Science And Engineering

More Questions from Web Technology and its Applications Module 2