zIndex style property
| A A | Font size |
|
|
|
Specifies or returns the stack level of positioned objects.
This element is useful if you want to create overlapping elements, like dialogs, tooltips or banners.
Elements with the same z-index are stacked back-to-front according to HTML flow.
The children of a stacked element are at the same stack level, if you want to use some overlap between them, you can use a minimum index of 0.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
| CSS page for this element: z-index |
Possible values:
The type of this property is string.
One of the following values: | Default. Determines the stacking order of the positioned element automatically based on its order in the document. | ||||||
| Takes the value of this property from the computed style of the parent element. | ||||||
| Integer that specifies the stack level. |
Default: auto.
Example HTML code 1:
This example illustrates the use of the z-index property:
|
|
||||
<head> <style> .zindex1 { z-index: 1; background-color: #00F9F9; width: 80px; height: 80px; position: absolute; top: 80px; left: 80px; } .zindex2 { z-index: 2; background-color: red; width: 80px; height: 80px; position: absolute; top: 140px; left: 145px; } </style> </head> <body> <div class="zindex2">z-index: 2</div> <div class="zindex1">z-index: 1</div> </body> |
||||
|
||||
|
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the zIndex property:
|
|
||||
<head> <style> #zindex1 { z-index: 1; background-color: #00F9F9; width: 80px; height: 80px; position: relative; top: 0px; left: 0px; } #zindex2 { z-index: 2; background-color: red; width: 80px; height: 80px; position: relative; top: -55px; left: 35px; } </style> <script> function ChangeZIndex (selectTag) { // Returns the index of the selected option var whichSelected = selectTag.selectedIndex; // Returns the selected option value var indexValue = selectTag.options[whichSelected].text; var firstDiv = document.getElementById ("zindex1"); firstDiv.style.zIndex = indexValue; firstDiv.innerHTML = "z-index: " + indexValue; } </script> </head> <body> <div id="zindex1">z-index: 1</div> <div id="zindex2">z-index: 2</div> <br /> Change the z-index property: <select size="5" onclick="ChangeZIndex (this)"> <option />0 <option selected="selected" />1 <option />2 <option />3 <option />4 </select> </body> |
||||
|
||||
|
Did you find this example helpful?
|
Supported by objects:
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.runtimeStyle, htmlElement.style
HTML elements:
a, abbr, acronym, address, b, bdo, big, blink, blockquote, body, button, caption, center, cite, code, col, colgroup, dd, del, dfn, dir, div, dl, dt, em, fieldset, font, form, h1, h2, h3, h4, h5, h6, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, label, legend, li, listing, marquee, menu, nobr, ol, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp
Related pages:
External links:
User Contributed Comments

