CSS - 在div中垂直对齐两个或多个(并排)元素
问题描述:
我试图在div中垂直对齐不同高度的两个元素:
I am trying to vertically align two elements with different heights in a div:
<div class="footer-icons">
<div id="footer-twitter">
<img src="images/twitter.png" width="40" alt="">
</div>
<div id="footer-fb">
<div class="fb-like" data-href="http://facebook.com/user" data-send="false" data-layout="button_count" data-width="160" data-show-faces="false" data-font="arial"></div>
</div>
</div>
twitter div的高度为40像素,fb div的高度为20像素。当前发生的是fb div垂直居中与twitter图像的底部边缘。这里是CSS:
The twitter div has a height of 40px, and the fb div has a height of 20px. What is currently happening is the fb div is vertically centered with the bottom edge of the twitter image. Here's the CSS:
.footer-icons{
padding-top:40px;
width:300px;
margin:auto;
text-align:center;
vertical-align:middle;
}
#footer-twitter{
display:inline-block;
}
#footer-fb{
display:inline-block;
}
我做错了什么?
答
将垂直对齐放在内部div上
Put the vertical align on the inner divs
#footer-twitter{
display:inline-block;
vertical-align:middle;
}
#footer-fb{
display:inline-block;
vertical-align:middle;
}