画布和 z 索引
我有以下 HTML 代码:
<div class="reflect" style="width: 348px; height: 327px; overflow-x: hidden; overflow-y: hidden; ">
<img id="image" class="reflected"
src="http://domain.com/1-1.png"
style="display: block; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial;">
<canvas width="348" height="54"
style="display: block; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: -50px;"></canvas>
</div>
我希望 canvas 元素出现在 IMG 下方。现在,画布位于图像的顶部,其中 50px 部分位于顶部(请参阅 margin-top: 50px)。我尝试为每个元素设置 z-index 但没有成功。需要你的帮助来解决这个问题。
I have the following HTML code:
<div class="reflect" style="width: 348px; height: 327px; overflow-x: hidden; overflow-y: hidden; ">
<img id="image" class="reflected"
src="http://domain.com/1-1.png"
style="display: block; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial;">
<canvas width="348" height="54"
style="display: block; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: -50px;"></canvas>
</div>
I want the canvas element to appear below the IMG. Right now, the canvas is on top of the image, 50px part of it on top (see margin-top: 50px). I've tried setting z-index to each element with no success. Need your help in solving this one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要查看元素的
absolute
定位和z-index
如果您绝对定位
img
,请设置z-index,然后然后从画布元素中删除margin-top
,这应该可以工作。You need to have a look at
absolute
positing of elements andz-index
If you position the
img
absolutely, set the z-index, and then remove themargin-top
from the canvas element, this should work.