HTML DOM zIndex Property
Complete Style Object Reference
Definition and Usage
The zIndex property sets the stack order of an element.
An element with
greater stack order is always in front of another element with lower stack
order.
Syntax
Object.style.zIndex=auto|number
|
Possible Values
| Value |
Description |
| auto |
The stack order is equal to its parents |
| number |
A number that defines the stack order of the element |
Tips and Notes
Tip: Elements can have negative stack orders.
Note: zIndex only works on elements that have been positioned, like
position:absolute;
Example
The following example changes the stack order of an element:
<html>
<head>
<style type="text/css">
#img1
{
position:absolute;
left:0px;
top:0px;
z-index:-1
}
</style>
<script type="text/javascript">
function changeStackOrder()
{
document.getElementById("img1").style.zIndex="1";
}
</script>
</head>
<body>
<h1>This is a Heading</h1>
<img id="img1" src="bulbon.gif" width="100" height="180">
<p>Default z-index is 0. Z-index -1 has lower priority.</p>
<input type="button" onclick="changeStackOrder()"
value="Change stack order" />
</body>
</html>
|
Try-It-Yourself Demos
zIndex
- Change the stack order of an element
Complete Style Object Reference
 |
|
Get Your Diploma!
W3Schools' Online Certification Program is the perfect solution for busy
professionals who need to balance work, family, and career building.
The HTML Certificate is for developers who want to document their knowledge of HTML, XHTML, and CSS.
The ASP Certificate is for developers who want to document their knowledge of ASP, SQL, and ADO.
|
|