Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap center 3 col-md-3 divs

I have a wrapper like so: <div class="community-images"></div>

and inside this wrapper I have 3 col-md-3 divs:

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

what I am trying to do is center these 3 divs inside the wrapper, how would I accomplish this ?

Here is the CSS:

.community-images {
  padding: 40px 0px 40px 0px;
}

.col-md-3 {
  border: 1px solid #ccc;
  padding: 10px;
  margin: 10px;
  min-height: 300px;
  box-shadow: 10px 10px 5px #888888;
}
like image 745
user979331 Avatar asked Jun 15 '15 13:06

user979331


People also ask

How do I center COL in Bootstrap 3?

My approach to center columns is to use display: inline-block for columns and text-align: center for the container parent. You just have to add the CSS class 'centered' to the row .

How do I align 3 divs in one row in HTML?

Three or more different div can be put side-by-side using CSS. Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side.

How do I center a col in Bootstrap?

Use d-flex justify-content-center on your column div. This will center everything inside that column. If you have text and image inside the column, you need to use d-flex justify-content-center and text-center . <div class="col text-center"> worked for me.

What is Col MD 4 in Bootstrap?

col-md-4: This class is used when the device size is medium or greater than 768px and the maximum width of container is 720px and you want the width equal to 4 columns.


1 Answers

For anyone using Bootstrap 4, this feature has been added: http://v4-alpha.getbootstrap.com/layout/grid/#variable-width-content

<div class="container">
  <div class="row justify-content-md-center">
    <div class="col col-lg-2">
      1 of 3
    </div>
    <div class="col-12 col-md-auto">
      Variable width content
    </div>
    <div class="col col-lg-2">
      3 of 3
    </div>
  </div>
  <div class="row">
    <div class="col">
      1 of 3
    </div>
    <div class="col-12 col-md-auto">
      Variable width content
    </div>
    <div class="col col-lg-2">
      3 of 3
    </div>
  </div>
</div>
like image 169
Alec Smart Avatar answered Sep 17 '22 18:09

Alec Smart