编辑
我应该说我有多个图像要连续放置。mdk 提供的解决方案有效,但每个图像都出现在新行上。
我有描述和图像。我将描述覆盖在图像顶部。目前它在图像的底部左对齐。我想让描述在水平和垂直方向上居中对齐,但这样做有困难。使用的图像尺寸为 320 x 240。
<!-- image -->
<div style="position: relative; left: 0; top: 0;">
<a href="test.html"> <img src = "test.png" style="position: relative; top: 0; left: 0; width: 320px;"></a>
<!-- description div -->
<div class='description'>
<!-- description content -->
<p class='description_content'>This is the description of the image</p>
<!-- end description content -->
</div>
<!-- end description div -->
</div>
<!-- end image div -->
</div>
<!-- end wrapper div -->
css
div.wrapper{
float:left; /* important */
position:relative; /* important(so we can absolutely position the description div */
padding: 5px;
}
div.description{
position:absolute; /* absolute position (so we can position it where we want)*/
bottom:0px; /* position will be on bottom */
left:0px;
/* styling bellow */
background-color:black;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size:18px;
font-weight:900;
color:white;
opacity:0.75; /* transparency */
filter:alpha(opacity=70); /* IE transparency */
}
p.description_content{
padding:10px;
margin:0px;
}