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:
- https://github.com/twitter/bootstrap/blob/master/less/variables.less
- https://github.com/twitter/bootstrap/blob/master/less/mixins.less
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…