Five equal columns in twitter bootstrap
Solution 1:
For Bootstrap 4
Bootstrap 4 now uses flexbox by default, so you get access to its magical powers straight out of the box. Check out the auto layout columns that dynamically adjust width depending on how many columns are nested.
Here's an example:
<div class="row">
<div class="col">
1 of 5
</div>
<div class="col">
2 of 5
</div>
<div class="col">
3 of 5
</div>
<div class="col">
4 of 5
</div>
<div class="col">
5 of 5
</div>
</div>
WORKING DEMO
For Bootstrap 3
A fantastic full width 5 columns layout with Twitter Bootstrap was created here.
This is by far the most advanced solution since it works seamlessly with Bootstrap 3. It allows you to re-use the classes over and over again, in pair with the current Bootstrap classes for responsive design.
CSS:
Add this to your global stylesheet, or even to the bottom of your bootstrap.css
document.
.col-xs-5ths,
.col-sm-5ths,
.col-md-5ths,
.col-lg-5ths {
position: relative;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;
}
.col-xs-5ths {
width: 20%;
float: left;
}
@media (min-width: 768px) {
.col-sm-5ths {
width: 20%;
float: left;
}
}
@media (min-width: 992px) {
.col-md-5ths {
width: 20%;
float: left;
}
}
@media (min-width: 1200px) {
.col-lg-5ths {
width: 20%;
float: left;
}
}
Put it to use!
For example, if you want to create a div element that behaves like a five column layout on medium screens and like two columns on smaller ones, you just need to use something like this:
<div class="row">
<div class="col-md-5ths col-xs-6">
...
</div>
</div>
WORKING DEMO - Expand the frame to see the columns become responsive.
ANOTHER DEMO - Incorporating the new col-*-5ths
classes with others such as col-*-3
and col-*-2
. Resize the frame to see them all change to col-xs-6
in responsive view.
Solution 2:
Use five divs with a class of span2 and give the first a class of offset1.
<div class="row-fluid">
<div class="span2 offset1"></div>
<div class="span2"></div>
<div class="span2"></div>
<div class="span2"></div>
<div class="span2"></div>
</div>
Voila! Five equally spaced and centered columns.
In bootstrap 3.0, this code would look like
<div class="row">
<div class="col-md-2 col-md-offset-1"></div>
<div class="col-md-2"></div>
<div class="col-md-2"></div>
<div class="col-md-2"></div>
<div class="col-md-2"></div>
</div>
UPDATE
Since bootstrap 4.0 uses Flexbox by default:
<div class="row">
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
</div>