A summary of the differences between Div CSS Absolute and relative _ experience Exchange

Source: Internet
Author: User
Detailed explanation of the relationship between the two, need to cooperate with examples, please first look at the example:

The following is a reference fragment:




<title>Div + CSS Example, wayhome ' s Blog</title>



Position:absolute;

top:5px;

right:20px;

 
Position:absolute;

left:20px;

bottom:10px;




Position:absolute;

top:5px;

left:5px;



position:relative;

left:150px;

 

width:300px; height:50px;



  
 

1


 

2


 

3


 

4


 

5


 
padding:20px 0 0 20px;
Position Absolute;
  
Position relative;

left:200px;

  

width:300px;

height:300px;

  
Position:absolute;

top:20px;

right:20px;

  
Position:absolute;

bottom:20px;

left:20px;

  
  
 
 






Absolute: Absolute positioning, CSS notation "position:absolute; ", it is positioned in two cases, as follows:

1. There is no setting for Top, right, Bottom or left, by default the parent's "content area origin" is the original point, the above example red section (parent yellow area has Padding attribute, "coordinate origin" and "content area origin" is different).

2. There are settings for Top, right, Bottom and left, and here are two different situations:

(1). The parent does not have a position attribute, the upper left corner of the browser (that is, Body) is positioned as "coordinate origin", the position is determined by the top, right, Bottom and left properties, the example green section above.

(2). The parent has the position attribute, the parent's "coordinate origin" is the original point, the above example is the light blue section.

Relative: relative positioning, CSS notation "position:relative; ", referring to the parent's" content area origin "as the original point, no parent to the Body's" content area origin "as the original point, the position is determined by the Top, right, Bottom, and left properties, and has the role of" open or occupy height ", the example orange section above.

Through the above examples and explanations, I believe that skilled use of absolute and relative is not a very difficult thing, we are surrounded by a lot of absolute and relative good examples, such as "NetEase 163 free Mail" Home (http://mail.163.com ), there is a lot of use.

Example code is passed in IE5.5, IE6, FF1.5, and OPERA9 tests.
  • 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.