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

标签 html css xhtml

有人可以提示我为什么我的 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/

相关文章:

javascript - 使用 ng-container 与模板的好处?

html - 我的整个 div 是可点击的。当指针在div区域时,我可以在链接上制作悬停效果吗?

css - Garamond 真的是网络安全字体吗?

javascript - 用于验证的 data-cfasync (W3C)

javascript - 如何将列表项用作表单中的值?

javascript - 全部删除按钮(带 Canvas 的绘画应用程序)

html - 撕裂式页脚不起作用

javascript - 为什么 jquery 代码不能在服务器上运行但可以在我的 PC 上运行?

php - 如何更改谷歌浏览器的接受 header ?

html - 固定 header CSS - 仅电子邮件注册表单