Cssposition:absolute Comprehensive understanding of the analysis

Source: Internet
Author: User
I. Characteristics of absolute positioning

Absolute positioning has the same characteristics as floating, that is, enveloping and destructive.

In terms of destruction, floating only destroys the height of the element, retains the width of the element, and the absolute positioning of the element height and width are not.

Take a look at the following code:

<!         DOCTYPE html>

Ii. general rules for absolute positioning:

When an element is absolutely positioned, it is completely detached from the document flow and is positioned relative to its containing block.

An absolutely positioned containing block, which is the closest positioned ancestor of the element.

If the ancestor element is a block-level element, the containing block is the inner margin boundary of the ancestor element, that is, the bounding rectangle.

If the ancestor element is an inline element, the containing block is the content boundary of the ancestor element, that is, the content area.

If there is no ancestor element that has been positioned, the containing block of the element is defined as the initial containing block.

Offset properties: Top, right, bottom, left.

If an absolutely positioned element does not have an offset property set, the position is not moved, although it is out of the document flow.

The offset property can be a negative value, positioning the element outside the containing block.

Here's the code:

<! DOCTYPE html>

Third, adjust the position of absolute positioning element with margin

Absolutely positioned elements, in addition to being able to offset using top, right, bottom, and left, can be precisely positioned with margin values and are better adaptive.

Example:

<! DOCTYPE html>

Discarding the offset attribute instead of using margin to adjust the absolute positioning element is the principle of:

An absolutely positioned element that, while not set at offset, is completely out of the document stream, but it is still in its original position.

The exact location of the offset attribute is determined by the inclusion block of the absolutely positioned element, which will have a completely different positioning result.

The use of margin for precise positioning, not dependent on anything else, more controllable.

Iv. absolute positioning and overall layout

How to use absolute positioning to the overall layout of the page?

Simple rough, not learn to waste!!!

<! DOCTYPE html>

The above CSS Position:absolute comprehensive understanding is the small part of the whole content to share to everyone, I hope to give you a reference, but also hope that we support topic.alibabacloud.com.

Related Article

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.