css - 居中嵌套 div 在 bootstrap 中不起作用

标签 css twitter-bootstrap

我有这个标记:

<div class="container">
<div class="row ">
    <div class="col-md-12">
        <div class="row">
            <div class="col-md-6 text-center">
    <h1>BLOG POST TITLE</h1>

    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod</p>

           </div>
       </div>
</div>
</div>

我期望 col-md-6 中的内容在 col-md-12 中居中,但这并没有发生。我也尝试过 margin:0 auto; 但结果相同。

这是一个fiddle.

如何让 col-md-6 的内容在 col-md-12 中居中?

最佳答案

为内部元素使用偏移量,在 Bootstrap 中,默认情况下,所有行都有 12 列。

        <div class="col-md-offset-3 col-md-6 text-center">
          ...
        </div>

官方文档中的更多详细信息:http://getbootstrap.com/css/#grid-offsetting

关于css - 居中嵌套 div 在 bootstrap 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22459028/

相关文章:

javascript - 在一个 div 中显示 2 个自定义数据属性项。例如 : Currency & Amount

html - 图标的 CSS background-position 只显示最后一个图标更多细节见代码

twitter-bootstrap - Bootstrap 4徽章没有改变颜色

CSS 无法在 Chrome 中使用 Twitter Bootstrap

javascript - 在 div 中拖放列表元素

html - DOM 元素变量以获得第 N 个结果?

javascript - 如何修改使用过的 css 框架生成的 css 内联元素?

html - 如何在扩展列表项中保持水平元素对齐?

javascript - 使用 twitter bootstrap 时如何使用 jquery 获取表单对象

javascript - 在 ASP.NET MVC 中选择页面加载时的选项卡