2012-02-02 82 views
2

的位置絕對是不可能的。 vertical-align:bottom; display:table-cell;會工作,但它需要居中。jQuery的對齊內底部的div

我需要裏面的div圖像對齊到底部。圖像高度不同。

我應該針對每個圖像和計算容器高度,並使用滯留者爲上邊距或有更簡單的解決方案?

謝謝!

+0

爲什麼是絕對定位出了問題? – 2012-02-02 22:31:21

回答

0

您可以設置「行高」和「文本對齊」的div屬性,然後設置DIV中的圖像的「垂直對齊」屬性。

div.images 
{ 
    width: 720px; 
    display: block; 
    text-align: center; 
    line-height: 720px; 
} 
div.images img 
{ 
    vertical-align: bottom; 
} 
0

你不必相對於整個頁面的絕對位置。您只需打開容器的定位相對:

$("#my_id").parent().position(position : "relative"); 

,然後內

$("#my_id").position(position : "absolute", left : ______, top : ______) 

或CSS絕對定位的元素,

#my_container { 
    position: relative; 
} 

#my_id { 
    position: absolute; 
    left: __; 
    top: __; 
} 
0

您可以將圖像添加爲背景和使用bottom center定位:

div { 
    background: url("path_to_img") no-repeat bottom center; 
    width: 500px; 
    height: 500px; 
    background-color: #e1e1e1; 
} 
0

你並不需要爲這個jQuery:

<div id="wrap"> 
    <img src="img/image.jpg" alt="" /> 
</div> 

#wrap { position: relative; } 
#wrap img { 
    position: absolute; /* display: block is implied */ 
    bottom: 0; 
} 
+0

事情比較複雜一點與本網站和IM抱歉,但CSS絕對是關閉的問題。 結束了與此 $( 「展.thumb」。)每個(函數(){ \t \t \t VAR H = $(本).height(); \t \t \t變種IH = $(此)。兒童( 'IMG')的高度(); \t \t \t $(本)。兒童( 'IMG')的CSS( 'marginTop',H-1H); \t \t }); – client 2012-02-03 08:26:22

+0

你應該發佈這個答案並接受它,所以這個問題可以被認爲是完整的 – BananaNeil 2012-02-03 11:08:39