我想让我的文字出现在我的背景图像上。我试图玩z-index
和定位,但似乎无法做到。如何使文字显示在图像顶部
这里是我的HTML:
<div id="float-left">
<div id="triangles">
<img src="img/trianglebackground.png" id="tripic">
</div>
<div id="float-left-text">
<img src="img/portrait.png" id="port">
</div>
</div>
这里是CSS我目前:
#tripic {
z-index:1;
height: 550px;
width: 500px;
text-align: center;
opacity: 0.2;
position: relative;
}
#float-left {
float: left;
/*background: url('img/trianglebackground.png') no-repeat center;*/
background-size:500px 550px;
background-color: #03C9A9;
height: 550px;
width: 50%;
z-index:0 ;
position: relative;
}
#float-left-text{
text-align: center;
z-index: 100;
position: absolute;
}
#port {
height: 200px;
width: 125px;
}
眼下,整个#floatlefttext
部分是背景图像的下方,而我会把它想在上面。我试图使用background-image
,但我不确定这将是获得我想要的结果的最佳方式。任何建议将是伟大的,谢谢!
哇,非常感谢!这是一个非常有用和彻底的答案。我会阅读这篇文章,看起来很有希望。再次感谢! – ohconfusedone
随时,很高兴我可以帮助:) – malinantonsson