The absolute, fixed, and relative differences of CSS position

Source: Internet
Author: User

First, we should understand the default value of position--static

Static

Default value, no positioning, element appears in normal stream, i.e. ignore top, bottom, left, right or Z-index declaration

Absolute

Creates an absolutely positioned element that is positioned relative to the first parent element other than the static anchor .

The position of the element is defined by the "left", "Top", "right" and "bottom" attributes.

Characteristics: Out of normal flow

Fixed

Generates an absolutely positioned element that is positioned relative to the browser window .

The position of the element is defined by the "left", "Top", "right" and "bottom" attributes.

Characteristics: Out of normal flow

Relative

Creates a relative positioned element, positioned relative to its normal position.

Therefore, "left:20" adds 20 pixels to the left position of the element.

Characteristics: No escape from normal flow

Absolute and fixed
Common

1. It will change the way the inline element is rendered, and display will be set to block

2, will let the elements out of normal flow, do not occupy space

3, the default will be overridden on the non-anchored elements, you can also adjust the overwrite order through the Z-index declaration

Different points

1. The root element of the absolute can be set, while the fixed root element is pinned to the current window (APP)

2, (commonly used) when you scroll, the distance between the fixed element and the window (application) is constant.

Absolute and Relative
Different points

1. Absolute refers to the upper-left corner of the parent element, and relative the original point of the reference element (for example, "left:20" adds 20 pixels to the leftmost position of the element)

2, relative Z-index can not define the parent-child relationship, must be the child on the parent; absolute multiple layers can change the layer overlap order using the Z-index attribute

Absolute, fixed, and relative differences in CSS position

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.