編輯
我應該說,我有多個圖像,我試圖把它放在一行。由mdk提供的解決方案有效,但每個圖像都顯示在新行中。如何在圖像的頂部垂直和水平居中對齊說明?
我有一個描述和圖像。我將圖片上的描述疊加在一起。目前它左對齊在圖像的底部。我想讓描述在水平和垂直方向上居中對齊,但是我很難做到這一點。所使用的圖像的大小是320×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;
}
是圖像總是相同的大小? –
我現在半睡不着,所以我不想做出正確的答案,但在這裏:http://jsfiddle.net/EWzwy/ –
@ScottSelby是的圖像總是相同的尺寸 – sharataka