<div class="row">
<div ng-repeat="tile in tiles" class="col-md-3"></div>
</div>
How can I make sure that these bootstrap columns are always centered, even if there is only 2 of them?
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.
Horizontal Alignment To horizontally align columns, we can use the justify-content classes. justify-content-start left align the columns. justify-content-center center aligns the columns. justify-content-end right align the columns.
Bootstrap uses a 12-column grid system that can update itself responsively based on screen size. There are only 38 highly composite numbers below the one million threshold, including 120, 2520, 5040, 55440 and 720720.
The Bootstrap grid has only 12 columns, so you should never have more than 12 columns in a row. You should have only 3 col-md-4 in each .
Add row-center
class to the row and col-center
to col-md-3 in this way:
<div class="row row-center">
<div ng-repeat="tile in tiles" class="col-md-3 col-center"></div>
</div>
.row-center {
text-align:center;
}
.col-center {
display:inline-block;
float:none;
}
Bootply Demo
Starting from bootstrap 4
this feature added!
you can use this class: justify-content-center
so your code should looks like:
<div class="container">
<div class="row justify-content-center">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
</div>
Check bootstrap documentation: https://getbootstrap.com/docs/4.0/layout/grid/#horizontal-alignment
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