Właściwość zIndex stylu
Przykład
Zmień kolejność stosu elementu <img>:
document.getElementById("img1").style.zIndex = "1";
Definicja i użycie
Właściwość zIndex ustawia lub zwraca kolejność stosu elementu pozycjonowanego.
Element o wyższym porządku stosu (1) zawsze znajduje się przed innym elementem o niższym porządku stosu (0).
Wskazówka: Element pozycjonowany to element z właściwością position ustawioną na: relatywną, bezwzględną lub stałą.
Wskazówka: ta właściwość jest przydatna, jeśli chcesz tworzyć nakładające się elementy.
Obsługa przeglądarki
Property | |||||
---|---|---|---|---|---|
zIndex | Yes | Yes | Yes | Yes | Yes |
Składnia
Zwróć właściwość zIndex:
object.style.zIndex
Ustaw właściwość zIndex:
object.style.zIndex = "auto|number|initial|inherit"
Wartości nieruchomości
Value | Description |
---|---|
auto | The browser determines the stack order of the element (based on its order in the document). This is default |
number | An integer that defines the stack order of the element. Negative values are allowed |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Szczegóły techniczne
Domyślna wartość: | automatyczny |
---|---|
Wartość zwrotu: | String, reprezentujący kolejność stosu elementu |
Wersja CSS | CSS2 |
Więcej przykładów
Przykład
Zmień wartość właściwości z-index elementu <div>:
document.getElementById("myDIV").style.zIndex = "-1";
Przykład
Zwróć wartość właściwości z-index elementu <img>:
alert(document.getElementById("img1").style.zIndex);
Powiązane strony
Samouczek CSS: Pozycjonowanie CSS
Odniesienie CSS: właściwość z-index
❮ Obiekt stylu