Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

5 Equal Spans in 1 Row - Twitter Bootstrap

Using the fluid grid layout I can get 4 equal spans:

<div class="row-fluid">
  <div class="span3">...</div>
  <div class="span3">...</div>
  <div class="span3">...</div>
  <div class="span3">...</div>
</div>

Or I can get 6 equal spans:

<div class="row-fluid">
  <div class="span2">...</div>
  <div class="span2">...</div>
  <div class="span2">...</div>
  <div class="span2">...</div>
  <div class="span2">...</div>
  <div class="span2">...</div>
</div>

But how do I get 5 equal spans?

like image 401
colmtuite Avatar asked Feb 27 '13 04:02

colmtuite


People also ask

How do I make 5 equal columns in Bootstrap?

Second example: instead of adding a number to each col , let bootstrap handle the layout, to create equal width columns: two "col" elements = 50% width to each col, while three cols = 33.33% width to each col. Four cols = 25% width, etc. You can also use . col-sm|md|lg|xl|xxl to make the columns responsive.

What is XS SM MD LG in Bootstrap?

The Bootstrap grid system has four classes: xs (for phones - screens less than 768px wide) sm (for tablets - screens equal to or greater than 768px wide) md (for small laptops - screens equal to or greater than 992px wide) lg (for laptops and desktops - screens equal to or greater than 1200px wide)

How many grid lines over which Bootstrap layout system can adapt are available in version 5?

Bootstrap's grid system can adapt across all six default breakpoints, and any breakpoints you customize. The six default grid tiers are as follow: Extra small (xs)


4 Answers

I have followed bootstraps methods for calculating widths and have come up with the following. You will want to follow the HTML structure of as follows:

<div class="row-fluid-5">
    <div class="span2">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</div>
    <div class="span2">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</div>
    <div class="span2">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</div>
    <div class="span2">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</div>
    <div class="span2">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</div>
</div>

Then, after you load bootstrap.css and bootstrap-responsive.css, load your custom.css file with the following:

/* CUSTOM 5 COLUMN SPAN LAYOUT
  *
  * based on http://gridcalculator.dk/
  * width => 1200, gutter => 15px, margin => 15px, columns => 5
  */
 .row-fluid-5 {
   width: 100%;
   *zoom: 1;
 }
 .row-fluid-5:before,
 .row-fluid-5:after {
   display: table;
   line-height: 0;
   content: "";
 }
 .row-fluid-5:after {
   clear: both;
 }
 .row-fluid-5 [class*="span"] {
   display: block;
   float: left;
   width: 100%;
   min-height: 30px;
   margin-left: 1.875%;
   *margin-left: 1.875%;

   -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
           box-sizing: border-box;
 }

 .row-fluid-5 .controls-row [class*="span"] + [class*="span"] {

   margin-left: 1.875%;
 }
 .row-fluid-5 [class*="span"]:first-child{
    margin-left: 0;
 }
 .row-fluid-5 .span2 {
   width: 18.5%;
   *width: 18.5%;
 }

 /* responsive ONLY */

 @media (max-width: 600px){ /* spans reduce to 100px then go full width */

    .row-fluid-5 [class*="span"]{
    margin-left: 0;
    float: left;
    width: 100%;
    padding: 10px; 
    }
 }

Check out the demo below to see how it works.

DEMO

like image 183
Paul Gemignani Avatar answered Oct 09 '22 05:10

Paul Gemignani


Considering that by default bootstrap is 12 columns, you cannot mathematically get 5 equal spans.

However, if you really need to (bad idea, more on that in a second), you can customize your bootstrap download to have 15 columns.

http://twitter.github.com/bootstrap/customize.html

Change the @gridColumns variable to 15, then use 5 columns all with a span3.

It is a bad idea though. Bootstrap is 12 columns because 12 works well. Using 12 gives you support for 1/4, 1/3, and 1/2 width columns. With a 15 column layout, you will only have support for 1/3rd width (and a lot of strange other sizes). Your call though, the setting is there.

like image 25
Mike Robinson Avatar answered Oct 09 '22 04:10

Mike Robinson


You need to generate custom grid (e.g. 10). There is no way to create 5 equal raws in 12 column grid

like image 26
Daniil Ryzhkov Avatar answered Oct 09 '22 05:10

Daniil Ryzhkov


Or you could add this to your css (or the bootstrap.css) - This is my preferred way to solve this. The "15" used to throw me a little bit, but just try to remind yourself it's 1/5th.

.col-xs-15,
.col-sm-15,
.col-md-15,
.col-lg-15 {
    position: relative;
    min-height: 1px;
    padding-right: 10px;
    padding-left: 10px;
}

.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;
    }
}

Then just use it like you would any other bootstrap class.

<div class="row">
    <div class="col-md-15 col-sm-3">
    ...
    </div>
</div>
like image 21
hardba11 Avatar answered Oct 09 '22 04:10

hardba11