【问题标题】:Center a div that is inline-block居中一个内联块的 div
【发布时间】:2013-10-18 09:44:04
【问题描述】:

我有一个 .container div,我想在页面上居中。

不幸的是,div 应该适合里面的表格。因此,如果表格占页面的 75%,我希望 .container 也占 75%。

我的 .container 看起来像这样:

.container{
  display:inline-block;
  background:#FFF;
  height:500px;
  max-width:80%;
}

我做了一个 JSFiddle here.

感谢大家的帮助!

【问题讨论】:

标签: css html centering


【解决方案1】:

text-align:center 添加到inline-block 元素的父元素会使它居中。

Updated jsFiddle here

在这种情况下,它将是:

body {
    text-align:center;
}

【讨论】:

    猜你喜欢
    • 2012-04-25
    • 2016-05-27
    • 1970-01-01
    • 1970-01-01
    • 2016-01-19
    • 1970-01-01
    • 2014-04-11
    • 2015-07-27
    • 2014-07-02
    相关资源
    最近更新 更多