Absolute position: absolute; relative position: relative, absoluterelative

Source: Internet
Author: User

Absolute position: absolute; relative position: relative, absoluterelative

1

When we want to use absolute positioning, we must have two conditions.
1 "must add a positioning attribute to the parent element. Generally, it is recommended to use position: relative (that is, set the parent element to relative positioning );
2. Add absolute position: absolute to the child element (set absolute position for the child element), and add the direction attribute (top, left, rigoal, bottom)

Absolute positioning is based on the parent element (if it does not have a parent element, or its parent element does not have the position: relative attribute set) it is located based on <body>. The absolute positioning will be out of the Document Stream (I .e., it will float and no longer occupy the original position)

Absolute Positioning

<!DOCTYPE html>


2. Add absolute positioning to the child element. If relative positioning is not added to the parent element, the absolute positioning of the child element is based on the body.

<! DOCTYPE html> 


3. Finally, add relative positioning to the parent element and add absolute positioning to the child element. Then, the absolute positioning of the child element is based on the parent element.

<! DOCTYPE html> 


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.