元素不会显示,似乎隐藏在背景图像后面?

jav*_*avi 4 html css xhtml

soneone可以给我一个暗示,为什么我的元素(id ="stuff")不会显示?

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
 <title>blah</title>
<style type="text/css" media="screen, print, projection">

body{     
    width: 100%;     
    height: 100%;     
    margin: 0;     
    padding: 0;      
}
img#background {     
    position: absolute;     
    top: 0;     
    left: 0;     
    width: 100%;    
    height: 100%; 
    margin:0;     
    padding:0;
} 
#stuff{
background: black;
height: 50px;
width: 100px;
z-index: 2;
}


</style> 
</head>
<body>
<img id="background" src="greenbackground.png" alt="Background Image" />
<div id="stuff"><p>stuff</p></div>



</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Ali*_*guy 5

给它一个静态以外的位置:

#stuff{
    background: black;
    height: 50px;
    width: 100px;
    z-index: 2;
    position:relative;
}
Run Code Online (Sandbox Code Playgroud)


JBr*_*oks 5

z-index仅适用于定位的元素(position:absolute,position:relative或position:fixed)。将位置线添加到#stuff将解决此问题。

#stuff{
 position:relative;
background: black;
height: 50px;
width: 100px;
z-index: 2;
}
Run Code Online (Sandbox Code Playgroud)