2015-06-29 36 views
1

我有每個滑塊5個圖像和所有不同的大小,我需要一種方法將所有圖像對齊到底部,以便它們都對齊良好,並且能夠在圖像之間添加相同的填充。對齊底部不同大小的圖像

我遇到的問題是所有圖像聚集在一起,並且圖像之間的填充不一致。

ul.building_images { 
 
\t margin: 0; 
 
\t padding: 0; 
 
\t } 
 

 
\t .building_images li { 
 
\t width: 270px; 
 
\t height: 270px; 
 
\t list-style-type: none; 
 
\t float: left; 
 
\t margin: 2px; 
 
\t margin-right: -62px; 
 
\t /*border: 1px solid #000;*/ 
 
\t position: relative; 
 
\t } 
 

 
\t .building_images li img { 
 
\t position: absolute; 
 
\t top: 0; 
 
\t left: 0; 
 
\t } 
 
\t img { 
 
\t } 
 

 
\t .building_images li:hover img { 
 
\t /*width: 273px;*/ 
 
\t height: 273px; 
 
\t /*background-color: blue;*/ 
 
\t z-index: 1; 
 
\t }
<div id="randomContainer"> 
 
\t <div class="container">  
 
\t  <div class="row">    
 
\t \t <ul class="building_images"> 
 
\t \t <li><img class="img1" src="<?php echourl(); ?>/images/slider/1.png" /> 
 
\t \t \t <div class="content_hidden1"><h3>Schools</h3> 
 
\t \t  <p>Learning environments are about more than books, papers and grades. It is about keeping the students and teachers comfortable in the classroom while saving the school as much money as possible. 
 
\t \t \t </p></div> 
 
\t \t </li> 
 
\t \t <li><img class="img2" src="<?php echourl(); ?>/images/slider/2.png" /> 
 
\t \t \t <div class="content_hidden2"><h3>Commmercial</h3><p>Commercial buildings use over 60% of the electricity in the US, making energy efficiency more important than ever. Perfection has been an industry leader in providing energy efficient solutions while keeping comfort and serviceability in mind.</p> 
 
\t \t  </div> 
 
\t \t </li> 
 
\t \t <li><img class="img3" src="<?php echourl(); ?>/images/slider/3.png" /> 
 
\t \t \t <div class="content_hidden3"><h3>Civic</h3> 
 
\t  <p>Whether a project for a courthouse, jail, police department or small office in City Hall, we know that we have to design the most functional, energy efficient solution for a tight budget.</p> 
 
\t  </div> 
 
\t \t </li> 
 
\t \t <li><img class="img4" src="<?php echourl(); ?>/images/slider/4.png" /> 
 
\t \t \t <div class="content_hidden4"><h3>WAREHOUSE/LOGISTICS</h3> 
 
\t \t  <p>Perfection designs and installs mechanical systems for warehouse and distribution facilities. 
 
\t \t  <a href="/"><img src="">test</a> 
 
\t \t  </p> 
 
\t \t  </div> 
 
\t \t </li> 
 
\t \t <li><img class="img5" src="<?php echourl(); ?>/images/slider/5.png" /> 
 
\t \t \t <div class="content_hidden5"><h3>Health Care</h3> 
 
\t  <p>Perfection understands the complexity of doing construction and maintenance services in an active health care facility. Communication, safety and proper project management are the keys to a successful outcome in this industry. 
 
\t \t </p></div> 
 
\t \t </li> 
 
\t \t </ul> 
 
\t \t </div> 
 
\t </div> 
 
</div>

+1

尋求調試幫助的問題(「爲什麼不是這個代碼工作?」)必須包含所需的行爲,特定的問題或錯誤以及在問題本身**中重現**所需的最短代碼。請參閱[**如何創建一個最小,完整和可驗證的示例**](http://stackoverflow.com/help/mcve) –

+0

您是否希望圖像在「li」元素底部對齊文字),還是希望圖片留在文字上方,但其底線應該在同一高度? –

+0

文字只是在點擊圖像時彈出,我已經發現了這些。 – Anthony

回答

2

DEMO OF ANSWER

這些圖像一堆因爲這個CSS屬性一起:

.building_images li { 
    margin-right: -62px; 
} 

通過編輯該值可以改變每個li元件之間的距離。嘗試例如30pxli的之間的恆定margin

.building_images li { margin-right: 30px; } 

接下來,您可以使用的CSS標籤position: absolute,你已經使用設置top: 0定位您li內部圖像。您可以將其更改爲bottom: 0

雖然你應該防止圖像拉伸比你的幻燈片更大。我已經完成了這項工作,將max-width: 100%添加到您的圖片中。

這是你的.building_images li可能是什麼樣子:

<style type="text/css"> 
ul { 
    margin: 0; 
    padding: 0; 
} 
.building_images li { 
    width: 80px;  /* Set your width */ 
    height: 150px; /* Set your height */ 
    margin: 0 30px 30px 0; /* Set your margins (top right bottom left) */ 
    list-style: none; 
    float: left; 
    position: relative; 
    background: red; /* Just for the demo, to see the <li> */ 
} 
.building_images li img { 
    max-width: 100% !important; /* Auto scale your images to full width */ 
    position: absolute; 
    top: auto; 
    left: 0; 
    right: 0; 
    bottom: 0; /* Align your images at the bottom */ 
} 
</style> 

我創建最小JSFIDDLE DEMO向您展示上面提到的兩個定位的結果。

+0

這很好。謝謝你。現在另一個曲線球。我在圖片上有一個懸停選項,這裏是CSS,有些圖片在懸停時調整大小,有些則不。 '.building_images li img:hover {0} {0} {*} {width:273px; */ max-width:105%!important; /* background-color:blue; */ z-index:1; }' – Anthony

+0

很高興我幫了忙。要解決懸停問題,您需要了解使用'max-width'。雖然'width:100%'表示「你必須是全寬」,'max-width:100%'表示「你可以是全寬」,如果你小一點,那就OK了,這就是爲什麼小圖片不能得到我爲你創建了一個小提琴來展示它的不同之處並創建一個修復:http:// jsfiddle。net/oys8pfw9/5/ 如果你想升級你的圖片,請更換每個'max-width:'width' width' –

+0

真棒,完美,我仍然能夠完成它留下最大寬度,我做了一些調整大小在沒有使用懸停的圖像上。非常感謝你的一切。 – Anthony