如何在div中垂直放置子元素 [英] How to center vertically child elements inside div

查看:614
本文介绍了如何在div中垂直放置子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

Possible Duplicate:
How to make an image center (vertically & horizontally) inside a bigger div

HTML代码:

<div class="promo_tumbs col_12">
    <div class="promo_tumb"></div>
    <div class="promo_tumb"></div>
    <div class="promo_tumb"></div>
    <div class="promo_tumb"></div>
    <div class="promo_tumb"></div>
</div>

CSS部分:

.promo_tumbs {
    height: 155px;
    background: #058;
}
.promo_tumb {
    height: 75px;
    width: 125px;
    background: #990000;
    float: left;
    margin: 0 10px;
    text-align: center;
}

如何垂直居中 .promo_tumb

推荐答案

阅读这篇关于垂直居中的文章。

Read this article on vertical centering.

http://www.jakpsatweb.cz/css/css-vertical -center-solution.html

如果您不希望支持IE7或更低版​​本,则可以使用 vertical-align:middle

If you dont wanna support IE7 or lesser then you can use vertical-align : middle.


  1. 设置显示 $ 中的表

  2. 设置 vertical-align & 显示 table-cell for
    .promo_tumb

  1. Set display to table in .promo_tumbs col_12
  2. Set vertical-align to middle & display to table-cell for .promo_tumb

它应该可以工作。

这篇关于如何在div中垂直放置子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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