有人可以提示我为什么我的 element(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>
最佳答案
z-index 仅适用于定位元素(position:absolute、position:relative 或 position:fixed)。将位置线添加到#stuff 将解决此问题。
#stuff{
position:relative;
background: black;
height: 50px;
width: 100px;
z-index: 2;
}
关于html - 元素不会显示,似乎隐藏在背景图像后面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6631583/