2013-11-02 40 views
2

我無法弄清楚沒有使用float:right或使用相對定位。如果我使用它,當人們放大和縮小時它會四處移動。我試圖弄清楚如何讓它保持在我放置它的位置,即使人們放大和縮小。我怎樣才能讓文本框粘在每個包裝div的頂部?

http://htmlcss.netii.net/

HTML結構:

<div class="staff-block">   
    <img class="staff-pics" /> 

    <div class="staff-text"> 
     <h3> 
     <p> 
    </div> 
</div> 

CSS:

.staff-block { /* Red */ 
    border: 1px dashed red; 
    display: block; 

} 

.staff-pics { /* Orange */ 
    border: 1px dashed orange; 
    display: ; 
    width:150px; 
    display: inline-block; 
    margin-bottom: 50px; 
} 

.staff-text { /* Yellow */ 
    border: 1px dashed yellow; 
    width: 70%; 
    font-size: 15px; 
    color: #FFCC00; 
    display: inline-block; 
} 

.staff-text h3 { /* Green */ 
    border: 1px dashed lime; 
    margin-bottom: 10px; 
    color: white; 
} 

.staff-text p { /* Blue */ 
    border: 1px dashed aqua; 
} 

回答

1

因爲它們已經inline-block元素,只需添加vertical-align:top

.staff-text { 
    vertical-align: top; 
} 

它的工作原理 - 我通過Chrome的開發工具..測試它

更新CSS:

.staff-text { 
    border: 1px dashed lime; 
    width: 70%; 
    font-size: 15px; 
    color: #FFCC00; 
    display: inline-block; 
    vertical-align: top; 
} 
+1

謝謝,我不知道該vertical-align屬性 – ekedin

+0

的一些原因,當我用文本編輯器打開它時,它不在開發工具之外工作。 – ekedin

+1

@ekedin它應該工作 - 檢查開發工具,看看是否有任何東西被覆蓋..也有可能是chaching ..否則將'vertical-align:top'添加到'divs' –

相關問題