📜 ⬆️ ⬇️

What nobody told you about z-index


The problem with z-index is that many simply do not understand how it works.
Everything described below is in the W3C specification. Unfortunately, not everyone reads it.

Description of the problem:


So, let us have HTML code consisting of 3 .
. , , : , , . , , . z-index , 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }


jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1
.
. , , : , , . , , . z-index
, 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }


jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1
 . 
. , , : , , . , , . z-index
, 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }


jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1
.
. , , : , , . , , . z-index
, 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }


jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1
 . 
. , , : , , . , , . z-index
, 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }


jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1
.
. , , : , , . , , . z-index
, 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }


jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1
 . 
. , , : , , . , , . z-index
, 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }

jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1
    .
    . , , : , , . , , . z-index
    , 1, z-index .

    HTML css .
    <div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
    .red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
    jsfiddle

    : , , :
    HTML / z-index /

    :
    , ( ).
    css, :
    div:first-child { opacity: .99; }

    jsfiddle

    , - . ? ? ? !
    , .

    :
    Z-index : , , .. z-index 5 z-index 2, ? .
    z-index. , .

    HTML , . . , , , , .

    z-index , : HTML. ( , , )

    ( ), . ( « » – , , : , ).

    , , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


    , . z-index .

    HTML . , . , , , z-index .

    :
    – ( )
    z-index auto
    1
  • .
    . , , : , , . , , . z-index
    , 1, z-index .

    HTML css .
    <div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
    .red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
    jsfiddle

    : , , :
    HTML / z-index /

    :
    , ( ).
    css, :
    div:first-child { opacity: .99; }

    jsfiddle

    , - . ? ? ? !
    , .

    :
    Z-index : , , .. z-index 5 z-index 2, ? .
    z-index. , .

    HTML , . . , , , , .

    z-index , : HTML. ( , , )

    ( ), . ( « » – , , : , ).

    , , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


    , . z-index .

    HTML . , . , , , z-index .

    :
    – ( )
    z-index auto
    1
    .
    . , , : , , . , , . z-index
    , 1, z-index .

    HTML css .
    <div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
    .red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
    jsfiddle

    : , , :
    HTML / z-index /

    :
    , ( ).
    css, :
    div:first-child { opacity: .99; }

    jsfiddle

    , - . ? ? ? !
    , .

    :
    Z-index : , , .. z-index 5 z-index 2, ? .
    z-index. , .

    HTML , . . , , , , .

    z-index , : HTML. ( , , )

    ( ), . ( « » – , , : , ).

    , , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


    , . z-index .

    HTML . , . , , , z-index .

    :
    – ( )
    z-index auto
    1
  • .
    . , , : , , . , , . z-index
    , 1, z-index .

    HTML css .
    <div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
    .red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
    jsfiddle

    : , , :
    HTML / z-index /

    :
    , ( ).
    css, :
    div:first-child { opacity: .99; }

    jsfiddle

    , - . ? ? ? !
    , .

    :
    Z-index : , , .. z-index 5 z-index 2, ? .
    z-index. , .

    HTML , . . , , , , .

    z-index , : HTML. ( , , )

    ( ), . ( « » – , , : , ).

    , , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


    , . z-index .

    HTML . , . , , , z-index .

    :
    – ( )
    z-index auto
    1
    .
    . , , : , , . , , . z-index
    , 1, z-index .

    HTML css .
    <div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
    .red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
    jsfiddle

    : , , :
    HTML / z-index /

    :
    , ( ).
    css, :
    div:first-child { opacity: .99; }

    jsfiddle

    , - . ? ? ? !
    , .

    :
    Z-index : , , .. z-index 5 z-index 2, ? .
    z-index. , .

    HTML , . . , , , , .

    z-index , : HTML. ( , , )

    ( ), . ( « » – , , : , ).

    , , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


    , . z-index .

    HTML . , . , , , z-index .

    :
    – ( )
    z-index auto
    1
  • .
    . , , : , , . , , . z-index
    , 1, z-index .

    HTML css .
    <div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
    .red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
    jsfiddle

    : , , :
    HTML / z-index /

    :
    , ( ).
    css, :
    div:first-child { opacity: .99; }

    jsfiddle

    , - . ? ? ? !
    , .

    :
    Z-index : , , .. z-index 5 z-index 2, ? .
    z-index. , .

    HTML , . . , , , , .

    z-index , : HTML. ( , , )

    ( ), . ( « » – , , : , ).

    , , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


    , . z-index .

    HTML . , . , , , z-index .

    :
    – ( )
    z-index auto
    1
    .
    . , , : , , . , , . z-index
    , 1, z-index .

    HTML css .
    <div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
    .red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
    jsfiddle

    : , , :
    HTML / z-index /

    :
    , ( ).
    css, :
    div:first-child { opacity: .99; }

    jsfiddle

    , - . ? ? ? !
    , .

    :
    Z-index : , , .. z-index 5 z-index 2, ? .
    z-index. , .

    HTML , . . , , , , .

    z-index , : HTML. ( , , )

    ( ), . ( « » – , , : , ).

    , , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


    , . z-index .

    HTML . , . , , , z-index .

    :
    – ( )
    z-index auto
    1
.
. , , : , , . , , . z-index
, 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }

jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1

.
. , , : , , . , , . z-index
, 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }

jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1

.
. , , : , , . , , . z-index
, 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }


jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1
.
. , , : , , . , , . z-index
, 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }


jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1

.
. , , : , , . , , . z-index
, 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }


jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1

.
. , , : , , . , , . z-index
, 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }


jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1

.
. , , : , , . , , . z-index
, 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }


jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1

.
. , , : , , . , , . z-index
, 1, z-index .

HTML css .
<div> <span class="red">Red</span> </div> <div> <span class="green">Green</span> </div> <div> <span class="blue">Blue</span> </div>
.red, .green, .blue { position: absolute; } .red { background: red; z-index: 1; } .green { background: green; } .blue { background: blue; }
jsfiddle

: , , :
HTML / z-index /

:
, ( ).
css, :
div:first-child { opacity: .99; }


jsfiddle

, - . ? ? ? !
, .

:
Z-index : , , .. z-index 5 z-index 2, ? .
z-index. , .

HTML , . . , , , , .

z-index , : HTML. ( , , )

( ), . ( « » – , , : , ).

, , z-index . , , z-index z-index, z-index z-index, . , z-index . z-index , . , z-index . , , ?


, . z-index .

HTML . , . , , , z-index .

:
– ( )
z-index auto
1

')

Source: https://habr.com/ru/post/166435/


All Articles