Created
December 18, 2015 04:15
-
-
Save dkrnl/a09696211616a823d236 to your computer and use it in GitHub Desktop.
Bootstrap: extra framework grid generation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Extra framework grid generation | |
// | |
// Based on bootstrap/grid-framework.less | |
.x-make-grid-columns(@columns: @grid-columns, @gutter-width: @grid-gutter-width, @prefix: ".col") { | |
// Common styles for all sizes of grid columns, widths 1-12 | |
.x-col(@index) { // initial | |
@item: ~"@{prefix}-xs-@{index}-of-@{columns}, @{prefix}-sm-@{index}-of-@{columns}, @{prefix}-md-@{index}-of-@{columns}, @{prefix}-lg-@{index}-of-@{columns}"; | |
.x-col((@index + 1), @item); | |
} | |
.x-col(@index, @list) when (@index =< @columns) { // general; "=<" isn't a typo | |
@item: ~"@{prefix}-xs-@{index}-of-@{columns}, @{prefix}-sm-@{index}-of-@{columns}, @{prefix}-md-@{index}-of-@{columns}, @{prefix}-lg-@{index}-of-@{columns}"; | |
.x-col((@index + 1), ~"@{list}, @{item}"); | |
} | |
.x-col(@index, @list) when (@index > @columns) { // terminal | |
@{list} { | |
position: relative; | |
// Prevent columns from collapsing when empty | |
min-height: 1px; | |
// Inner gutter via padding | |
padding-left: ceil((@gutter-width / 2)); | |
padding-right: floor((@gutter-width / 2)); | |
} | |
} | |
.x-col(1); // kickstart it | |
} | |
.x-float-grid-columns(@class, @columns: @grid-columns, @gutter-width: @grid-gutter-width) { | |
.x-col(@index) { // initial | |
@item: ~".col-@{class}-@{index}-of-@{columns}"; | |
.x-col((@index + 1), @item); | |
} | |
.x-col(@index, @list) when (@index =< @columns) { // general | |
@item: ~".col-@{class}-@{index}-of-@{columns}"; | |
.x-col((@index + 1), ~"@{list}, @{item}"); | |
} | |
.x-col(@index, @list) when (@index > @columns) { // terminal | |
@{list} { | |
float: left; | |
} | |
} | |
.x-col(1); // kickstart it | |
} | |
.x-calc-grid-column(@index, @class, @columns, @type) when (@type = width) and (@index > 0) { | |
@item: ~".col-@{class}-@{index}-of-@{columns}"; | |
@{item} { | |
width: percentage((@index / @grid-columns)); | |
} | |
} | |
.x-calc-grid-column(@index, @class, @columns, @type) when (@type = push) and (@index > 0) { | |
@item: ~".col-@{class}-push-@{index}-of-@{columns}"; | |
@{item} { | |
left: percentage((@index / @grid-columns)); | |
} | |
} | |
.x-calc-grid-column(@index, @class, @columns, @type) when (@type = push) and (@index = 0) { | |
@item: ~".col-@{class}-push-0-of-@{columns}"; | |
@{item} { | |
left: auto; | |
} | |
} | |
.x-calc-grid-column(@index, @class, @columns, @type) when (@type = pull) and (@index > 0) { | |
@item: ~".col-@{class}-pull-@{index}-of-@{columns}"; | |
@{item} { | |
right: percentage((@index / @grid-columns)); | |
} | |
} | |
.x-calc-grid-column(@index, @class, @columns, @type) when (@type = pull) and (@index = 0) { | |
@item: ~".col-@{class}-pull-0-of-@{columns}"; | |
@{item} { | |
right: auto; | |
} | |
} | |
.x-calc-grid-column(@index, @class, @columns, @type) when (@type = offset) { | |
@item: ~".col-@{class}-offset-@{index}-of-@{columns}"; | |
@{item} { | |
margin-left: percentage((@index / @grid-columns)); | |
} | |
} | |
// Basic looping in LESS | |
.x-loop-grid-columns(@index, @class, @columns, @type) when (@index >= 0) { | |
.x-calc-grid-column(@index, @class, @columns, @type); | |
// next iteration | |
.x-loop-grid-columns((@index - 1), @class, @columns, @type); | |
} | |
// Create grid for specific class | |
.x-make-grid(@class, @columns: @grid-columns, @gutter-width: @grid-gutter-width) { | |
.x-float-grid-columns(@class, @columns, @gutter-width); | |
.x-loop-grid-columns(@columns, @class, @columns, width); | |
.x-loop-grid-columns(@columns, @class, @columns, pull); | |
.x-loop-grid-columns(@columns, @class, @columns, push); | |
.x-loop-grid-columns(@columns, @class, @columns, offset); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment