2 回答
TA贡献2011条经验 获得超2个赞
使用z-index,position: relative;和position: absolute;.
这是您的 HTML:
<body>
<img src="" id="image" style="width:270px;height:270px;"/>
<img src="" id="image1" style="width:270px;height:270px;"/>
This is a text!
</body>
然后添加CSS:
img {
position: relative;
z-index: 1;
}
div {
position: absolute;
top: 0px; //To see the difference
}
代码笔: https: //codepen.io/marchmello/pen/ExjqGYQ
TA贡献1828条经验 获得超3个赞
您应该用于z-index覆盖文本和图像:
img {
position: absolute;
z-index: 2;
width: 200px;
}
div {
position: relative;
z-index: 1;
color: black;
}
<img src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg" />
<div>This is text over the image that goes on for a while</div>
- 2 回答
- 0 关注
- 119 浏览
添加回答
举报