I want to divide bootstrap
row into 5 equal parts. It includes 12-col-md
, so how i can divide it into equal 5 parts?
Can anyone help me to solve this problem?
I want to divide bootstrap
row into 5 equal parts. It includes 12-col-md
, so how i can divide it into equal 5 parts?
Can anyone help me to solve this problem?
A great way to resolve this is here!
By default Bootstrap does not provide grid system that allows us to create five columns layout, but as you can see it’s quite simple. At first you need to create default column definition in the way that Bootstrap do it. I called my classes col-..-15.
.col-xs-15, .col-sm-15, .col-md-15, .col-lg-15 { position: relative; min-height: 1px; padding-right: 10px; padding-left: 10px; }
Next you need to define width of new classes in case of different media queries.
.col-xs-15 { width: 20%; float: left; } @media (min-width: 768px) { .col-sm-15 { width: 20%; float: left; } } @media (min-width: 992px) { .col-md-15 { width: 20%; float: left; } } @media (min-width: 1200px) { .col-lg-15 { width: 20%; float: left; } }
Now you are ready to combine your classes with original Bootstrap classes. For example, if you would like to create div element which behave like five columns layout on medium screens and like four columns on smaller ones, you just need to use something like this:
<div class="row"> <div class="col-md-15 col-sm-3"> ... </div> </div>
Old bootstrap Version
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>
Five equally spaced and centered columns.
<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>
Custom Styles
.container {width:100%; float:left;}
.col1{ width:20%; float:left}
Latest Table style
.container {width:100%;display:table;}
.col1{ width:20%; display:table-cell;}
You can use something like
<div class="container">
<div class="col-sm-2 col-sm-offset-1"></div>
<div class="col-sm-2"></div>
<div class="col-sm-2"></div>
<div class="col-sm-2"></div>
<div class="col-sm-2"></div>
</div>
the first container will have offset so you will have the same margin (col-sm-1) on the left and right side with 5 equal containers inside.
it is quite simple if you are using bootstrap 4, not sure if it also works in bootstrap 3
<div class="container-fluid">
<h2>Bootstrap 4 Five Columns</h2>
<h5>Full-width (within .container-fluid)</h5>
<div class="row">
<div class="col">
<img src="//placehold.it/640x480" class="img-fluid">
</div>
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
</div>
You can use the row-cols-*
(eg: row-cols-3
, row-cols-md-3
) class for your requirement.
<div class="container">
<div class="row row-cols-2">
<div class="col">Column</div>
<div class="col">Column</div>
<div class="col">Column</div>
<div class="col">Column</div>
</div>
</div>
for more details Visit to official bootstrap site
<div class="row">
<div class="col-md-7">
<div class="row">
<div class="col-md-4 bg-danger">1</div>
<div class="col-md-4 bg-success">2</div>
<div class="col-md-4 bg-danger">3</div>
</div>
</div>
<div class="col-md-5">
<div class="row">
<div class="col-md-6 bg-success">4</div>
<div class="col-md-6 bg-danger">5</div>
</div>
</div>
</div>
You can use bootstrap-4 default 'col' property to solve this issue.
<div class="row no-gutters">
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
</div>
This will auto divide the given space into 5 equal parts.
Note: This can create issues in case if you want to show 3 columns on any other screen. Let's say if you want to show 5 columns in a row on medium screens then you can add class "col-md" on each element. But if you need 3 columns in a row on sm screens then you will face issues.
You can use span2
to utilize maximum amount of space.
Please find the code:
<div class="row-fluid">
<div class="span2">1</div>
<div class="span2">2</div>
<div class="span2">3</div>
<div class="span2">4</div>
<div class="span2">5</div>
</div>
Use this css property in your custromScript.css file to use in large Device
.col-lg-2-0 {
position: relative;
width: 100%;
padding-right: 15px;
padding-left: 15px;
-ms-flex: 0 0 20%;
flex: 0 0 20%;
max-width: 20%;
}
and use class col-lg-2-0
instead of col-lg-2
which will divide four columns
You can customize the css of bootstrap. You need import the scss files in a your own custom.scss file. Then you have to use compile custom.scss to css in another file. For ex: custom.css. Checkout this link for more detailed information. Bootstrap Theming
In custom.scss file
$grid-columns:15;
@import "node_modules/bootstrap/scss/bootstrap";
Then you can use col-{breakpoint}-3 in your project to have 5 equal width columns.
CAREFUL
This will be global. You have to change other files too if you have used default 12 point grid system elsewhere in your project.
I would suggest to use table instead of bootstrap for dividing it into 5 parts and inside each column again you can use bootstrap grid.
This answer may help you this
But if you have any other issues that you can't go with the above way please comment below.