Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center divs in row in bootstrap?

Tags:

html

css

I want to center my 7 divs and I don't know really how to do it. Any idea? I don't want to change margin all elements individually, as you can see on the picture divs are not centered compared to my buttons and there's a 12 column bootstrap problem

screenshot

<style type="text/css">
.properbut{
height: 180px;
display: block;
margin-left: auto;
margin-right: auto;
display: table-cell;
vertical-align: middle;

}

.fonts{
font-family:Georgia,serif;
color:#4E443C;
font-variant: small-caps; 
text-transform: none; 
font-weight: 100; 
font-size:   30px
}
</style>

<div class="container">
<br><br><br><br>

<div class="jumbotron">
    <br><br><br><br><br><br>
    <div class="row">
                    <div class ="col-md-2">
                    </div>

                    <div class ="col-md-1 ">
                       <img src="<?php echo asset_url();?>media/img/kalendarz/pon.png" style="height: 60px;">
                    </div>

                    <div class ="col-md-1 ">
                        <img src="<?php echo asset_url();?>media/img/kalendarz/wto.png"  style="height: 60px">
                    </div>


                    <div class ="col-md-1 ">
                        <img src="<?php echo asset_url();?>media/img/kalendarz/sro.png" style="height: 60px">
                    </div>


                    <div class ="col-md-1 ">
                        <img src="<?php echo asset_url();?>media/img/kalendarz/czw.png" style="height: 60px">
                    </div>


                    <div class ="col-md-1 ">
                        <img src="<?php echo asset_url();?>media/img/kalendarz/pia.png" style="height: 60px">
                    </div>


                    <div class ="col-md-1 ">
                        <img src="<?php echo asset_url();?>media/img/kalendarz/sob.png" style="height: 60px">
                    </div>


                    <div class ="col-md-1">
                        <img src="<?php echo asset_url();?>media/img/kalendarz/niedz.png" style="height: 60px">
                    </div>

                    <div class ="col-md-3">
                    </div>

    </div>
    <br><br><br><br><br><br>

    <div class="row container" >
            <div> 
                <button class="properbut btn btn-primary col-md-3 fonts" type="submit" style="margin-left: 130px;">Powtórki</button>
            </div>
            <div class="col-md-3" >

                    <p class="text-center fonts" style="margin-top: 7px; font-size: 30px;">Co dzisiaj zrobisz aby osiągnąć swój cel?</p>

            </div>

            <div> 
                <button class="properbut btn btn-warning col-md-3 fonts"  type="submit">Lekcje audio</button>
            </div>
    </div>
    <br><br><br><br><br><br><br><br>
    <br><br><br><br>

</div>

like image 447
tom Avatar asked Feb 15 '15 18:02

tom


People also ask

How do I center a div in a row in bootstrap 4?

1 — Vertical Center Using Auto Margins One way to vertically center is to use my-auto . This will center the element within it's flexbox container (The Bootstrap 4 . row is display:flex ). For example, h-100 makes the row full height, and my-auto will vertically center the col-sm-12 column.

How do I center a div in bootstrap 5?

Aligning content to the center of the DIV is very simple in Bootstrap 5, You just have to convert the div into a flex box using d-flex class property and then use the property align-items-center to vertically align the content in the middle of the div.

How do I center a div horizontally?

Center Align Elements To horizontally center a block element (like <div>), use margin: auto; Setting the width of the element will prevent it from stretching out to the edges of its container.


1 Answers

CSS Style:

/* centered columns styles */
.row-centered {
text-align:center;
}
.col-centered {
display:inline-block;
float:none;
/* reset the text-align */
text-align:left;
/* inline-block space fix */
margin-right:-4px;
}

HTML:

<div class="row row-centered">

<div class ="col-md-1 col-centered">
   <img src="http://placehold.it/100x100" style="height: 60px;">
</div>

<div class ="col-md-1 col-centered">
   <img src="http://placehold.it/100x100" style="height: 60px;">
</div>

<div class ="col-md-1 col-centered">
   <img src="http://placehold.it/100x100" style="height: 60px;">
</div>

<div class ="col-md-1 col-centered">
   <img src="http://placehold.it/100x100" style="height: 60px;">
</div>

<div class ="col-md-1 col-centered">
   <img src="http://placehold.it/100x100" style="height: 60px;">
</div>

<div class ="col-md-1 col-centered">
   <img src="http://placehold.it/100x100" style="height: 60px;">
</div>

<div class ="col-md-1 col-centered">
   <img src="http://placehold.it/100x100" style="height: 60px;">
</div>

</div><!-- row -->

enter image description here

This should help you fix it.

like image 114
michaelsangma Avatar answered Nov 14 '22 22:11

michaelsangma