Why is the z-index style not applied to the <body> element?

The style z-indexallows you to control which order fields are colored. For example, you can create a child below its parent:

#parent {
  background: rgba(33, 33, 33, 0.7);
}
#child {
  width: 100px;
  height: 100px;
  background: yellow;
  position: relative;
  z-index: -1;
}
<div id="parent"><div id="child"></div></div> 
Run code

However, when the parent is a tag <body>, it no longer behaves as expected:

body {
  background: rgba(33, 33, 33, 0.7);
}
#child {
  width: 100px;
  height: 100px;
  background: yellow;
  position: relative;
  z-index: -1;
}
<body>
  <div id="child"></div>
</body>
Run code

The CSS specification §9.9.1 states (primary focus):

. ( ), "z-index", "auto". . CSS , 'opacity [CSS3COLOR].

:

  • , .
  • ( ).
  • , -, - .
  • .
  • inline, inline-level, .
  • 0 0.
  • ( ).

<body> , , , <body> , .

HTML <html> . , <body> z-index?


( Russian Stack Overflow.)

+4
5

, html , body, . CSS 2.1 :

, HTML- HTML XHTML "html", "transparent" "background-color" "none" "background-image", HTML "BODY" "body" XHTML, .

, , html :

html { 
  background-color: white;
}

body {
  background: rgba(33, 33, 33, 0.7);
}
#child {
  width: 100px;
  height: 100px;
  background: yellow;
  position: relative;
  z-index: -1;
}
<body>
  <div id="child"></div>
</body>
+4

<body> - static. .

, z-index , position:static, body, static

, z-index position:static

: {position: relative}?

body . , z-index, siblings, . body parent, z- .

+6

, , , , Ian Hickson Tantek Celik, CSS.

W3C, spec z-index body.

:

  • z-index (, body), z-index

  • z- sibling, , -

    ... z- . , . , , ....

  • z-index position: fixed body, .


Tantek Celik:

z-index: . , BODY (. )?

z-index.

z-index .

< BODY STYLE = "z-index: 0; background-color: # 456789;" > < < P STYLE = "z-index: -1; color: #fedcba;" > , , <EM> ( "z-index" "-1" ). </EM>
</ >

, z-index, , :

http://www.w3.org/TR/REC-CSS2/visuren.html#z-index

z-index " : ", z-index .

Tantek

:

,

(: , z-index , , , , , - .)

:

< body style = "z-index = 0; background-color = green;" >

< p style = "z-index = -1; position: relative; top: 50; left: 20" > !! </ >
< > !! </ >
</ >

P BODY, CSS2 ( , :) z- -, . z- .

"!" "!!" BODY, BODY P .

!!! , , , , , , , .!!!

() z-index=-1 a position: fixed ( .) , , , , , BODY.

- ranjit

:

,

, .

HTML. , / .

: , (XML, HTML,...)

: z- . , . , , ,....

, CSS2, , z- ..

, z- CHILD z-. , , z-, z- .

: - , , , , .

,

- ranjit

http://lists.w3.org/Archives/Public/www-style/1999Aug/0131.html

+1

, .

<body> , z-index?

"" ?

z-index, , , html CSS - .

0

The <body>default tag remains at the bottom of the stack. It simply cannot be installed, as it will always be the smallest possible value.

Source: Adobe Forums

-one
source

All Articles