Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap fluid row width

in bootstrap-responsive.css

.row-fluid .span10{
    width: 91.45299145299145%;
    *width: 91.39979996362975%;
}

I was configuring the sizing, but am curious as to how they derived these numbers, and why are they accurate to 14 decimal places?

like image 802
Saad Avatar asked Sep 12 '12 02:09

Saad


1 Answers

They start with three values, which can be user-defined:

@gridColumns: 12;
@gridColumnWidth: 60px;
@gridGutterWidth: 20px;

Edit: on Bootstrap 3.0+, the variables are now:

@grid-columns
@grid-gutter-width
@grid-float-breakpoint   // the point at which the navbar stops collapsing

And calculate fixed row width:

@gridRowWidth: (@gridColumns * @gridColumnWidth) + (@gridGutterWidth * (@gridColumns - 1));

Then they go fluid:

@fluidGridColumnWidth: percentage(@gridColumnWidth/@gridRowWidth);
@fluidGridGutterWidth: percentage(@gridGutterWidth/@gridRowWidth);

And finaly, generate all the spans (that is a bit confusing):

.spanX (@index) when (@index > 0) {
  (~".span@{index}") { .span(@index); }
  .spanX(@index - 1);
}

.span (@columns) {
      width: (@fluidGridColumnWidth * @columns) + (@fluidGridGutterWidth * (@columns - 1));
      *width: (@fluidGridColumnWidth * @columns) + (@fluidGridGutterWidth * (@columns - 1)) - (.5 / @gridRowWidth * 100 * 1%);
}

.row-fluid {
  // generate .spanX and .offsetX
  .spanX (@gridColumns);
  .offsetX (@gridColumns);
}

As you see, LESS does the divisions and multiplications.

See it yourself:

  1. https://github.com/twitter/bootstrap/blob/master/less/variables.less
  2. https://github.com/twitter/bootstrap/blob/master/less/mixins.less
like image 149
albertedevigo Avatar answered Oct 10 '22 16:10

albertedevigo