2013-10-25 91 views
0

我試圖讓圖片獲得「.other-wrap」以便與左側的圖片垂直對齊。我嘗試添加邊距或邊框,但出於某種原因,這會推動「.other-wrap」向下並進一步偏離對齊方式。任何人都可以解釋是什麼導致了這種行爲,以及我可以添加到「.other-wrap」以使其對齊而不更改html結構。CSS內聯塊對齊問題

fiddle

HTML:

<div id="588970897807405-list" class="main"> 
<div id="588970897807405" class="main-wrap"> 
    <div class="inner-wrap"> 
     <div class="inner-name-wrap" style="font-size: 10pt;"> 
     <div class="inner-name">header</div> 
     </div> 
     <div class="inner-img-wrap"> 
     <img id="588970897807405-event-img" class="inner-img" src="http://nodogaboutit.files.wordpress.com/2012/10/j04310181.jpg"> 
     </div> 
     <div class="formatted-footer-wrap" style="font-size: 10pt;"> 
     <div class="footer">footer</div> 
     </div> 
    </div> 
    <div class="other-wrap"> 
     <div class="other-inner"> 
     <div class="other-img-wrap"><img class="other-img" width="120" height="120" src="http://www.petfinder.com/wp-content/uploads/2012/11/99059361-choose-cat-litter-632x475.jpg"></div> 
     </div> 
    </div> 
</div> 

CSS:

.main .inner-img{ 
vertical-align:middle; 
margin:auto; 
display:block; 
width:120px; 
height:120px; 
top:0px; 
} 

.other-wrap{ 

    /*border:solid black 15px;*/ 
    margin:15px; 
} 

.main .inner-name-wrap{ 
    white-space:nowrap; 
    width:150px; 
    font-size:14px; 
    text-overflow:ellipsis; 
    font-weight:normal; 
    display:block; 
    color:white; 
    background:black; 
} 

.main .formatted-footer-wrap{ 
    color:white; 
    display:block; 
    font-size:10px; 
    width:150px; 
    background:black; 
} 

.main .other-wrap{ 
    display:inline-block; 
    font-size:12px; 
} 

.main .formatted-time-wrap{ 
    display:none; 
    font-size:10px; 
} 

.inner-wrap{ 
    display:inline-block; 
    border:solid hsl(0, 100%, 100%) 1px;  
} 
+0

真的覺得你需要花更多的時間與此有關。我沒什麼投票權,但我接近這個。原因:您試圖實現默認行爲,並且解決方案需要其他人爲您解構代碼,並找出導致默認行爲不起作用的原因。我建議剝離所有這些,直到它完成它應該做的事情,然後開始添加事物,直到找到破壞它爲止。 –

回答

1

看來你需要vertical-align

嘗試vertical-align: middle

.main-wrap{ 
    font-size: 0; /* To fix extra space due to whitespaces in HTML */ 
} 
.other-wrap, .inner-wrap{ 
    display:inline-block; 
    vertical-align: middle; 
    margin: 15px; 
} 

Demo