html – Bootstrap:如何在列内对齐内容?

参见英文答案 > How do you get centered content using Twitter Bootstrap?22个
一个简单的用例场景是使用图像或Bootstrap列中的任何其他内容.通常这些内容需要横向居中.
<div class="container">
    <div class="row">
        <div class="col-sm-4 col-md-4 col-lg-4 text-center">
            <img class="img-responsive" src="img/some-image.png" title="this image needs to be centered">
        </div>
        <div class="col-sm-8 col-md-8 col-lg-8">
            some content not important at this moment
        </div>
    </div>
</div>

在3.1.0版中,添加类文本中心将图像置于列内.但我被迫转到版本3.3.4以解决其他一些问题,这种行为(文本中心)现在已经被破坏了.
我遗留的问题是如何将图像或其他内容置于列中.
我想避免必须将类添加到包含的元素,因为这容易出错或需要另一个包含div.

解决方法

想要居中的形象?非常简单,Bootstrap有两个类,.center-block和text-center.

在图像为BLOCK元素的情况下使用前者,例如,向img添加img-responsive类使img成为块元素.如果您知道如何在Web控制台中导航并查看元素的应用样式,则应该知道这一点.

不想上课?没问题,这是CSS bootstrap使用的.您可以为元素创建自定义类或编写CSS规则以匹配Bootstrap类.

// In case you're dealing with a block element apply this to the element itself 
.center-block {
   margin-left:auto;
   margin-right:auto;
   display:block;
}

// In case you're dealing with a inline element apply this to the parent 
.text-center {
   text-align:center
}

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些