Explain Positioning elements in CSS


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 to whatsapp

More Questions from Web Technology and its Applications Module 2

Explain the basic table Structure . Create an HTML Document for the following figure.
OneTwo
ThreeFour

View

Write short note on radio buttons and check boxes?


View
What is Responsive Design? Explain the components that make responsive web design. Why its important ? explain in detail.
View
Approaches to CSS Layout .
Explain fixed Layout and Liquid Layout with example each. List liquid and Fixed layout Advantages and limitations.
View
Explain Positioning Elements in CSS?
(or)
Explain the different ways of position Elements In CSS layout techniques
View
Explain the role of display and visibility properties in CSS with examples.
View
Discuss <table> element along row spanning and column
View