Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

css - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...