I personally summarize the four positions in css, cssposition

Source: Internet
Author: User

I personally summarize the four positions in css, cssposition

1. positon: static; static location (Default)

All elements in the standard document stream are static positioning

2. positon: relative; relative positioning

  Keep away from the standard Document Stream, "keep your hometown in trouble and separate shadows"

Features: If relative positioning is set and the top, left, right, and bottom attributes are set, the box will be offset at the original position of the box in the future.

The purpose of relative positioning: Generally, it is not used for "capping effect". It has two functions:

(1) fine-tuning Elements

(2) Absolute Positioning Reference, sub-parent

You can use left and right to describe the offset of the right and left boxes. You can use top and bottom to describe the offset of the bottom and top boxes.

Position: relative; top: 10px; left: 10px; // move 10px down from the original position to the right
Position: relative; top:-10px; left:-10px; // move 10px to the left relative to the original position

3. position: absolute; absolute positioning

  Exit standard Document Stream

Features: (1) if this element does not have a parent element, top, left, right, and bottom will be located relative to the browser window in the future.

(2) If the absolute positioning element has a parent element but the parent element is not relatively located, the top, left, right, and bottom are located relative to the browsing window.

(3) If the absolute positioning element has a parent element and the parent element has a location (non-static), the absolute positioning element offset is based on its own parent element.

(4) The element after absolute positioning will not occupy the position on the page

4. position: fixed; fixed Positioning

Exit standard Document Stream

Fixed positioning purpose: Some Small advertisements on the page must be fixed in a position on the page

 

Conclusion: when writing a page in the future, the most commonly used is not absolute or relative positioning, but absolute positioning and relative positioning.

Standard: Sub-parent (use absolute positioning for sub-elements and relative positioning for parent elements)

  

  

 

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.