Search code examples
center

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


I can't get bootstrap to center the content in the div. Here's my code:

<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>


Solution

  • As indicated by Parth Shah in the comments, the text-center class will do what you want. You can see this in the snippet if you properly include the scripts and styles 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>

    When posting here, always try to include your code snippet as accurately as possible, so the issues can be properly debugged. Hope showing this working snippet helps you. Cheers.