多次提出类似问题(如何在图像上放置文字),但每个解决方案都说明要制作一个相对放置的容器,并将图像和文字放在里面。将文字置于绝对图像
但是如果容器需要是绝对的?
我希望图像是绝对的,以跨越整个页面的宽度,而不受包装宽度的限制:包装器设置了宽度,图像容器应该忽略此并且是全屏,文本应该漂浮在图像上方。
这里是一个fiddle其中图像没有忽略包装的宽度
.splash_image {
position: relative;
left: 0;
top: 2%;
height: 600px;
overflow: hidden;
z-index: 1;
}
.splash_image img {
width: 100%;
position: absolute;
}
.splash_title {
color: red;
position: absolute;
}
.wrapper {
width: 50%;
}
<div class="wrapper">
<div class="splash_image">
<img src="http://fc07.deviantart.net/fs34/f/2008/290/6/4/Large_Tree_Stock_by_HauntingVisionsStock.jpg" alt="test image">
<div class="splash_title">Test title to go here on image</div>
</div>
</div>
所以删除'位置:relative'从'.splash_image' – j08691
什么是.splash_image默认的定位是什么?当我删除相对时,它不再对图像溢出产生影响。 举例来说,如果你改变了.splash_image高度60PX,而不是600和.splash_image删除相对位置,它不裁剪 https://jsfiddle.net/2tpbx12x/3/ – auto