如何使文本和/或图像居中 bootstrap 3.37?

How do I center a text and or image bootstrap 3.37?

我无法 bootstrap 将内容置于 div 的中心。这是我的代码:

<div class="container">
    <div class="col-xs-12">
        <div class="col-xs-12 col-md-6-offset-3 img-responsive center-block" id='banner'>
            <img src="img/5dd71e4f41bb16ac366892d3c2e99fdb.jpg">
            <h2>We know our customers best. Voted best online store 3 years running.</h2>
        </div>
    </div>
</div>

正如 Parth Shah 在评论中指出的那样,text-center class 会做你想做的事。如果你正确地包含了脚本和样式,你可以在代码片段中看到这一点 bootstrap depends on.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<div class="container">
    <div class="col-xs-12">
        <div class="col-xs-12 col-md-6-offset-3 img-responsive center-block text-center" id='banner'>
            <img src="img/5dd71e4f41bb16ac366892d3c2e99fdb.jpg">
            <h2>We know our customers best. Voted best online store 3 years running.</h2>
        </div>
    </div>
</div>

在此处发帖时,请务必尽可能准确地包含您的代码片段,以便正确调试问题。希望显示此工作片段对您有所帮助。干杯。