Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering columns using media queries bootstrap

I am trying to work on responsive web design, specifically on centering images that are within a column container when hitting screen size of 576px. I've tried this statement that I have seen elsewhere:

@media(max-width: 576px)
{
.first-pic-container {
    float: none;
    margin: 0 auto;

}

But it doesn't do much. I have also tried using Bootstrap's offset class but that doesn't do anything either.

Here's the relevant HTML:

<div class="col-sm-4 first-pic-container">
    <img class="first-step" src="step1image.png" alt="firstpic">
                <div class= "row">
                    <div class="col-sm-12 col-md-12 col-lg-10 first-p-container">
     <p class="step-one-p"> Enter the classes you are looking to take for next semester! </p>
                    </div>
                </div>
            </div>

And the codepen for visual reference. I added borders around the firstpic and first-pic-container which I am trying to center: https://codepen.io/gkunthara/pen/VWdrYj

like image 935
brownmamba Avatar asked Dec 12 '25 05:12

brownmamba


2 Answers

Give text-align: center to first-pic-container

@media(max-width: 576px) {
        .first-pic-container {
            text-align: center;
        }
    }
like image 169
Supraja Ganji Avatar answered Dec 14 '25 17:12

Supraja Ganji


Images are a inline elements by default so you only need to add text-align: center; to it's parent element. If you want to use margin: 0 auto; then you need to set the image to display: block;

like image 36
Lee Wise Avatar answered Dec 14 '25 19:12

Lee Wise



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!