【发布时间】:2014-10-21 15:06:42
【问题描述】:
我有两个 img 元素,我希望第一个 image.png 位于透明 image.png 后面。我尝试了很多不同的东西(z-index、透明背景颜色、rgba 背景颜色、绝对定位和相对定位、将一个嵌套在 div 中,使它们都成为 div)。现在我一直在尝试使用透明的 .png 图像。图像 .png 实际上在它后面,但它仍然通过它显示。请帮忙。
html:
<body>
<main class="site-wrapper">
<div class="carnival"></div>
<div id="images">
<img id="divbox" src="images/divbox.png">
<img id="clown1" src="images/clown1.png">
</div>
</main>
</body>
js:(我在 js b/c 中做了样式,我有兴趣学习如何这样做):
//styles
//divbox:
document.getElementById('divbox').style.display = "inline-block";
document.getElementById('divbox').style.transform = "skew(-2deg)";
document.getElementById('divbox').style.marginTop = "21%";
document.getElementById('divbox').style.marginLeft = "47.6%";
document.getElementById('divbox').style.height = "200px";
document.getElementById('divbox').style.width = "200px";
document.getElementById('divbox').style.border = "1px solid orange";
document.getElementById('divbox').style.position = "absolute";
document.getElementById('divbox').style.zIndex = "2";
//clown1:
document.getElementById('clown1').style.display = "inline-block";
document.getElementById('clown1').style.transform = "rotate(90deg)";
document.getElementById('clown1').style.marginTop = "21%";
document.getElementById('clown1').style.marginLeft = "53%";
document.getElementById('clown1').style.border = "1px solid green";
document.getElementById('clown1').style.position = "relative";
document.getElementById('clown1').style.zIndex = "1";
感谢您的帮助,如果我能回答问题,请告诉我。
更新:
对不起,没有更清楚。我现在已经获得了另一张图像后面的图像,但是由于上面的图像是透明的,所以后面的图像正在显示。我该如何阻止这个?
这是正在发生的事情的一个示例:
http://oi61.tinypic.com/2mw9egx.jpg
请注意橙色边框在顶部,所以它肯定在顶部。
更新 2:
这应该很清楚我想要什么。再次抱歉造成混乱:
【问题讨论】:
-
不清楚你想做什么。
-
拜托,拜托,请使用样式表!
-
很想知道这应该是什么样子。
-
不要使用#ids,因为你可能会拥有多个,或者至少添加类,这样你就可以为所有具有 class="clown"
-
@nepeo 他根本不应该使用 js,但对于所有不改变的人使用 css
标签: javascript html css z-index transparent