2

Here is my code sample. in full-width of the browser everything looks fine. But when I resize it, the images (cards) are more towards the left side (not centered). How can I fix this?

HTML code:

<div  class="container-fluid">          
        <div class="row ">
            <div class="col-md-2">
                <figure class="imghvr-fold-up">
                    <figcaption class="text-center">
                        Hello                           
                    </figcaption>                        
                    <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
                </figure>              
            </div>
            <div class="col-md-2">
                <figure class="imghvr-fold-up">
                    <figcaption class="text-center">
                        Hello                           
                    </figcaption>                        
                    <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
                </figure>    
            </div>
            <div class="col-md-2">
                <figure class="imghvr-fold-up">
                    <figcaption class="text-center">
                        Hello                           
                    </figcaption>                        
                    <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
                </figure>    
            </div>
            <div class="col-md-2">
                <figure class="imghvr-fold-up">
                    <figcaption class="text-center">
                        Hello                           
                    </figcaption>                        
                    <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
                </figure>    
            </div>
            <div class="col-md-2">
                <figure class="imghvr-fold-up">
                    <figcaption class="text-center">
                        Hello                           
                    </figcaption>                        
                    <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
                </figure>    
            </div>
            <div class="col-md-2">
                <figure class="imghvr-fold-up">
                    <figcaption class="text-center">
                        Hello                           
                    </figcaption>                        
                    <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
                </figure>    
            </div>
        </div>
    </div>

Since I'm using Bootstrap v4, it should automatically adjust according to the page. But here is what I experience...

See the image

the_dempa
  • 41
  • 8

3 Answers3

1

You can try using a spacer class on the image when on smaller screens mx-sm-auto, for more info on these see here: https://v4-alpha.getbootstrap.com/utilities/spacing/

Mike Sheward
  • 315
  • 1
  • 7
0

Add margin:auto and display: block to image to center it

Fiddle

.img-thumbnail{margin:auto;display:block}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div  class="container-fluid">          
        <div class="row ">
            <div class="col-md-2">
                <figure class="imghvr-fold-up">
                    <figcaption class="text-center">
                        Hello                           
                    </figcaption>                        
                    <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
                </figure>              
            </div>
            <div class="col-md-2">
                <figure class="imghvr-fold-up">
                    <figcaption class="text-center">
                        Hello                           
                    </figcaption>                        
                    <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
                </figure>    
            </div>
            <div class="col-md-2">
                <figure class="imghvr-fold-up">
                    <figcaption class="text-center">
                        Hello                           
                    </figcaption>                        
                    <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
                </figure>    
            </div>
            <div class="col-md-2">
                <figure class="imghvr-fold-up">
                    <figcaption class="text-center">
                        Hello                           
                    </figcaption>                        
                    <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
                </figure>    
            </div>
            <div class="col-md-2">
                <figure class="imghvr-fold-up">
                    <figcaption class="text-center">
                        Hello                           
                    </figcaption>                        
                    <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
                </figure>    
            </div>
            <div class="col-md-2">
                <figure class="imghvr-fold-up">
                    <figcaption class="text-center">
                        Hello                           
                    </figcaption>                        
                    <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
                </figure>    
            </div>
        </div>
    </div>
Znaneswar
  • 3,329
  • 2
  • 16
  • 24
0

Apply display: inline-block; to the img tag then apply text-align: center; to the parent;

In your code, you have applied display: block; to the image tag. Where now image act as a blocked element. That's why your image is not aligned in the center.

I have applied text-align: center; for imghvr-fold-up, because I can handle the caption and images in a single point.

Output:

//CSS
.img-thumbnail {
  display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid">
    <div class="row ">
        <div class="col-md-2 text-center">
            <figure class="imghvr-fold-up">
                <figcaption class="">
                    Hello
                </figcaption>
                <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
            </figure>
        </div>
        <div class="col-md-2">
            <figure class="imghvr-fold-up text-center">
                <figcaption class="">
                    Hello
                </figcaption>
                <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
            </figure>
        </div>
        <div class="col-md-2">
            <figure class="imghvr-fold-up text-center">
                <figcaption>
                    Hello
                </figcaption>
                <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
            </figure>
        </div>
        <div class="col-md-2">
            <figure class="imghvr-fold-up text-center">
                <figcaption>
                    Hello
                </figcaption>
                <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
            </figure>
        </div>
        <div class="col-md-2">
            <figure class="imghvr-fold-up text-center">
                <figcaption>
                    Hello
                </figcaption>
                <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
            </figure>
        </div>
        <div class="col-md-2">
            <figure class="imghvr-fold-up text-center">
                <figcaption>
                    Hello
                </figcaption>
                <img src="http://via.placeholder.com/200x200" class="img-thumbnail" alt="Cinque Terre">
            </figure>
        </div>
    </div>
</div>

Demo at codepen.

Satheesh Kumar
  • 2,205
  • 1
  • 16
  • 31