Css z-index cascade sequence

Source: Internet
Author: User

What is this?

The Z-index attribute determines the level of HTML elements. The element level is relative to the position of the element on the Z axis (in contrast to the Y axis of the X axis. A higher Z-index value means that the element is closer to the top in the stacked order. The stacked order is displayed along the vertical line axis.

To clearly describe how Z-index works, the above picture exaggerated the relationship between stacked elements in the visual position.

Natural cascade order

In an HTML page, the natural cascade Order (that is, the order of elements on the Z axis) is determined by many factors. The following is a list. The list items are displayed in a stacked environment (stacking context. Currently, no suitable Chinese translation is found. It should be the stacked environment where the stacked elements are located). None of the items in this list are assigned the Z-index attribute.

The background and border of the element will create a stacking Context

Reference:
· Stacking contexts elements with negative values are arranged in the order in which they appear (the lower the level, the higher the level)
· Unpositioned and unfloating block-level elements are arranged in order of appearance
· Unpositioned and floating elements are arranged in the order of appearance
· Inline elements are arranged in order of appearance
· The elements to be located are arranged in the order of appearance

The Z-index attribute changes the natural cascade order when it is correctly used.

Of course, unless the elements have been positioned to display in overlapping forms, the order of the elements will not be particularly obvious. Below, the box with the negative margin is displayed to illustrate the natural cascade order.

Full perspective: css z-index properties blue ideal: http://www.blueidea.com/tech/web/2009/7060.asp

Z-index is a magic attribute, so many effects on the front-end will involve it.

What is it? Try it.

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Meta name = "keywords" content = "Tomi-Eric"/>
<Meta name = "Description" content = "Tomi-Eric, exercise instance"/>
<Meta name = "author" content = "Tomi-Eric"/>
<Meta name = "Copyright" content = "Tomi-Eric, exercise instance"/>
<Title> simple XHTML page </title>
<Style type = "text/CSS">
# Main {position: relative}
# Layer-1, # Layer-2, # Layer-3, # Layer-4, # Layer-5 {position: absolute; width: 500px; Height: 300px}
# Layer-1 {top: 10px; left: 10px; Background: # CCC}
# Layer-2 {top: 30px; left: 50px; Background: # f00}
# Layer-3 {top: 50px; left: 100px; Background: # ff0}
# Layer-4 {top: 100px; left: 150px; Background: # f90}
# Layer-5 {top: 150px; left: 200px; Background: #999}
</Style>
<SCRIPT type = "text/JavaScript">
Function reset (){
VaR select_id = "layer-" + $ ("select_id"). value;
$ (Select_id). style. zindex + = 10;
VaR DIV = $ ("Main"). getelementsbytagname ("Div ");
Showzindex ("layer-", Div );
}
Function $ (ID ){
If (typeof (ID) = "string "){
Return document. getelementbyid (ID );
}
}
Function showzindex (ID, Div ){
For (VAR I = 0; I <= div. Length-1; I ++ ){
Alert (ID + (I + 1) + ":" + Div [I]. style. zindex );
}
}
</SCRIPT>
</Head>
<Body>
<Select name = "select_id" id = "select_id">
<Option value = "1" selected> 1 </option>
<Option value = "2"> 2 </option>
<Option value = "3"> 3 </option>
<Option value = "4"> 4 </option>
<Option value = "5"> 5 </option>
</SELECT>
<Input type = "button" value = "tuning" onclick = "RESET ()">
<Div id = "Main">
<Div id = "layer-1"> layer-1 </div>
<Div id = "layer-2"> layer-2 </div>
<Div id = "layer-3"> layer-3 </div>
<Div id = "layer-4"> layer-4 </div>
<Div id = "layer-5"> layer-5 </div>
</Div>
</Body>
</Html>

 

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.