Z-index 不适用于背景图像
对于以下 CSS -
.competition .banner .image {
background: url("{{ STATIC_URL }}images/comp-banner.jpg") no-repeat;
display: inline-block;
position: relative;
}
和 HTML -
<div class="banner">
<span class='image'>
</span>
</div>
<div class="info">
<div class="main-info">
{{ competition.description }}
</div>
</div>
我无法弄清楚如何将 description
放在背景图像之上。我尝试为所有 div
、span
等设置 Z 索引,但似乎没有任何效果。我如何将文本放在背景图像之上?
For the following CSS -
.competition .banner .image {
background: url("{{ STATIC_URL }}images/comp-banner.jpg") no-repeat;
display: inline-block;
position: relative;
}
And HTML -
<div class="banner">
<span class='image'>
</span>
</div>
<div class="info">
<div class="main-info">
{{ competition.description }}
</div>
</div>
I cannot figure how to put the description
on top of the background-image. I've tried setting the Z-index for all the div
's, span
's, etc. but nothing seems to work. How would I put the text on top of the background image here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
但描述在
main-info
里面...设置position:relative
到主div和position:absolute; z-index: 50
给孩子...这应该可以做到,而不是仅仅做一些top
,bottom
... 保持在应该的位置but the description is inside
main-info
... setposition: relative
to the main div andposition: absolute; z-index: 50
to the child... this should do it, than just do sometop
,bottom
... to stay where it should