WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

CSS Layout - The position Property


The position property indicates the kind of situating technique utilized for a component .It can likewise put a component behind another, and indicate what ought to happen when a component's substance is too big.


The position Property

The position property indicates the kind of situating strategy utilized for an element.

There are four diverse position esteems:

  • static
  • relative
  • fixed
  • absolute

Elements are then situated utilizing the best, base, left, and right properties .


position: static;

HTML components are situated static by default.

Static situated components are not influenced by the best, base, left, and right properties.

A static situated component is constantly situated by the typical stream of the page.

This <div> component has position: static;

Here is the CSS that is used:

Example

div.static {
    position: static;
    fringe: 3px strong blue;
}
Try it yourself »

position: relative;

An component with position: relative; is situated in respect to its typical position.

The properties top, right, base, and left can be utilized to determine .

This <div> component has position: relative;

Here is the CSS that is used:

Example

div.relative {
    position: relative;
    left: 30px;
    outskirt: 3px strong green;
}
Try it yourself »

position: fixed;

An component with position: fixed; is situated in respect to the viewport, which implies it generally remains in a similar spot regardless of whether the page is looked over. The best, right, base, and left properties are utilized to position the element.

A settled component does not leave a hole in the page where it would ordinarily have been located.

Notice the settled component in the lower-right corner of the page. Here is the CSS that is used:

Example

div.fixed {
    position: fixed;
    base: 0;
    right: 0;
    width: 300px;
    outskirt: 3px strong #73AD21;
}
Try it yourself »
This <div> component has position: fixed;

position: absolute;

An component with position: absolute; is situated in respect to the closest situated precursor (rather than situated with respect to the viewport, as fixed).

However; if a flat out situated component has no situated predecessors, it utilizes the archive body, and moves alongside page scrolling.

Note: A "positioned" component is one whose position is anything with the exception of static.

Here is a straightforward example:

This <div> component has position: relative;
This <div> component has position: supreme;

Here is the CSS that is used:

Example

div.relative {
    position: relative;
    width: 300px;
    tallness: 150px;
    fringe: 3px strong blue;
}

div.absolute {
    position: absolute;
    top: 80px;
    right: 0;
    width: 200px;
    tallness: 100px;
    fringe: 3px strong green;
}
Try it yourself »