Style zIndex Property
- Forrige side widows
- Næste side alignContent
- Gå tilbage til niveauet over HTML DOM Style Object
Definition and Usage
zIndex
Sets or returns the stacking order of the positioned element.
elements with a higher stacking order (1) are always in front of elements with a lower stacking order (0).
Tip:Positioning elements are position property Set to:relative
,absolute
or fixed
elements.
Tip:This property is very useful if you want to create overlapping elements.
See also:
CSS Tutorial:CSS positionering
CSS Reference Manual:z-index property
Example
Example 1
Change the stacking order of the <img> element:
document.getElementById("img1").style.zIndex = "1";
Example 2
Change the z-index property value of the <div> element:
document.getElementById("myDIV").style.zIndex = "-1";
Example 3
Return the z-index property value of the <img> element:
alert(document.getElementById("img1").style.zIndex);
Syntax
Return zIndex property:
object.style.zIndex
Set zIndex property:
object.style.zIndex = "auto|number|initial|inherit"
Property value
Value | Description |
---|---|
auto | The browser determines the stacking order of the element (based on its order in the document). Default. |
number | An integer that defines the stacking order of the element. Negative values are allowed. |
initial | Sets this property to its default value. See initial. |
inherit | Inherits this property from its parent element. See inherit. |
Technical details
Default value: | auto |
---|---|
Return value: | A string representing the stacking order of the element. |
CSS version: | CSS2 |
Browserkompatibilitet
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
- Forrige side widows
- Næste side alignContent
- Gå tilbage til niveauet over HTML DOM Style Object