CSS Page Layout tutorial: Layer Overlay 5 Principles-----Reprint

Source: Internet
Author: User

First, make clear the concepts that need to be used in the article:

    1. Static positioning: Position:static (the default value for the Position property).
    2. Dynamic positioning: position:relative or Position:absolute or position:fixed.
    3. Ancestor element: Any element that contains the element.
    4. Parent element: The ancestor element that directly contains the element.
    5. Sibling elements: elements that have a common parent element.

Note: These concepts are customized for authors and are used only for this article.

Reference:

It's a very important word about sibling elements, and it needs to be explained in detail here.

  1. <div>
  2. <div></div>
  3. <div id= "a" ></div>
  4. <div></div>
  5. <div></div>
  6. <div></div>
  7. <div></div>
  8. </div>
  9. <div id= "F" >
  10. <div></div>
  11. <div id= "B" ></div>
  12. <div id= "C" ></div>
  13. <div></div>
  14. <div></div>
  15. <div></div>
  16. </div>

In this example, div#a and div#b are not "peer elements", and only elements like div#b and div#c that have the same parent div#f can be called "sibling elements."

End of quote

then take a look at these five rules :

Rule One : When peer elements are positioned the same way, and there is no Z-index setting, HTML is on the latter.

rule two : When peer elements are dynamically positioned and have z-index settings, the Z-index value is large.

Click here to test

Rule Three : the localization of peer elements in different ways, dynamic positioning on the home.

Click here to test

Rule Four : non-sibling elements, when arbitrary accesses than either and its ancestor elements do not have a dynamic layout, HTML on the latter.

Click here to test

rule Five : "Important" non-sibling elements, when arbitrary accesses than either or its ancestor elements have dynamic positioning, simultaneously looking up dynamically positioned ancestor elements, and respectively, from the highest level of the ancestor (or itself) to compare.

  1. <div id= "AB" style= "Position:absolute;" >
  2. <div id= "A" style= "position:relative; z-index:100; " >
  3. <div id= "A_inner1" >
  4. <div id= "A_inner2" >
  5. <div id= "A_inner3" style= "position:relative; z-index:98; " >
  6. <div id= "A_inner4" >
  7. <div id= "A_inner5" >
  8. </div>
  9. </div>
  10. </div>
  11. </div>
  12. </div>
  13. </div>
  14. <div id= "B" >
  15. <div id= "B_inner1" >
  16. <div id= "B_inner2" >
  17. <div id= "B_inner3" style= "position:relative; z-index:99; " >
  18. <div id= "B_inner4" >
  19. </div>
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. </div>

Case 1: z-index of child elements no matter how big, the parent element is large.

Case 2: The parent element is under, and the child element can also reside.

Case 1, Condition 2 combined with extended comparison.

In fact, the first four points are the basis, only the 5th more difficult to understand, here to explain in detail:

In this example, we compare the cascade relationships between Div#a_inner5 and Div#b_inner4.
To the next level of the ancestral element div#ab which they share, Div#a_inner5 's ancestral elements include: Div#a,div#a_inner1,div#a_inner2,div#a_inner3,div#a_inner4;div#b_ Inner4 's ancestral elements include: Div#b,div#b_inner1,div#b_inner2,div#b_inner3.
Then analyze their ancestral elements with dynamic positioning: The elements of div#a_inner5 that contain dynamic positioning are: the elements of the div#a,div#a_inner3;div#b_inner4 ancestor element are: Div#b_inner3.
Then compare them with the highest level: div#a > #div #b_inner3.

The parent element, the child element can also reside in the situation, is the use of non-sibling elements in the ancestor element with dynamic layout, its comparison is not position:static, and its ancestor elements can be compared by the location of HTML.

End of quote

Of course, sometimes there are special cases, such as flash, such as IE6 in the select can not be covered, these are abnormal situations, you can search their own related articles.

CSS Page Layout tutorial: Layer Overlay 5 Principles-----Reprint

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.