【发布时间】:2015-07-29 07:34:29
【问题描述】:
我的滚动框中的图片很少,我需要一些文字来覆盖该图片。 图片数量可以是动态的,数量不必是6,而且必须是水平滚动而不是垂直。以下是我的代码,
<style type="text/css">
.imgtext {
margin-left: -300px;
}
</style>
<div id="hcontainer" style="width: 600px;">
<div id="inner_container" style="overflow: auto; width: 2500px;">
<img src="1.jpg" width="400px" height="200px" /><span class="imgtext">My new_1 text</span>
<img src="2.jpg" width="400px" height="200px" /><span class="imgtext">My new_2 text</span>
<img src="3.jpg" width="400px" height="200px" /><span class="imgtext"> My new_3 text</span>
<img src="4.jpg" width="400px" height="200px" /><span class="imgtext"> My new_4 text</span>
<img src="5.jpg" width="400px" height="200px" /><span class="imgtext">My new_5 text</span>
<img src="6.jpg" width="400px" height="200px" /><span class="imgtext">My new_6 text</span>
</div>
</div>
如您所见,文字出现在图像上方,但图像因此而折叠,这看起来不太好。我研究了相对父定位和绝对子定位的解决方案,但我不允许修改 div 样式/css 属性。所以,在 div 样式中使用绝对和相对解决方案是行不通的!我可以玩img & span 标签和css属性。
我可以使用 jquery/javascript,它可以移动文本并将其放置在相应的图像上。但我无法自己解决。谁能帮帮我?
【问题讨论】:
-
“我不允许修改 div 样式”是什么意思?
-
使用 span 上的相对位置和负左值
-
我正在与一个团队合作,并且对 div 有许多其他依赖项。因此,修改 div 样式会影响网页中的其他内容。我从中取出样本并在这里分享
-
@FabrizioCalderan 这样做会折叠我的图像:|
-
你用left代替margin-left了吗?
标签: javascript jquery html css