Understanding position Five properties in CSS

Source: Internet
Author: User

In the actual development of the page layout, the use of position, the positioning of the block-level elements of the nesting effect is always not very understanding, here to do a few tests

In general, we can easily get a definition in the list:

Static: The default value. No positioning, elements appear in the normal stream (ignoring top, bottom, left, right, or z-index declarations).

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.

Inherit: Specifies that the value of the position property should be inherited from the parent element.

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.

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.

Overall:

static , is the normal document flow sequence, the default, equivalent to no positioning!

fixed , is relative to the browser window, is your scroll bar how to scroll, he is still that position, think is "sticky" on the window!

  inherit , is the value of the Position property inherited from the parent element,

Absolute , is the original position of the out-of-document flow is not to continue to occupy, if his parent element has been positioned in either absolute or relative, it will be relative to his parent element to locate, If his parent element is not positioned, then it is positioned relative to the body. That is to say absolute definitely has the reference!

relative , is not out of the original position of the document flow will continue to occupy, it is only relative to their original position to locate!

The first three are easy to understand, for the combination of absolute and relative, several tests have been done

Testing (absolute and relative)

1. Separate absolute and relative

Relative in Relative,absolute in 2.relative

Absolute in absolute,relative in 3.absolute

  

<! DOCTYPE html>

In fact, many times, the online experience, a lot of miscellaneous, their own practice, to really understand

Understanding position Five properties in CSS

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.