CSS - 在div中垂直对齐两个或多个(并排)元素 [英] CSS - vertically align two or more (side by side) elements in a div

查看:759
本文介绍了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;
}

这篇关于CSS - 在div中垂直对齐两个或多个(并排)元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆