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;
}
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 .
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With