layout.less 1.62 KB
@row-prefix-cls: ~"@{css-prefix}row";
@col-prefix-cls: ~"@{css-prefix}col";

.make-row(@gutter: @grid-gutter-width) {
    position: relative;
    margin-left: (@gutter / -2);
    margin-right: (@gutter / -2);
    height: auto;
    .clearfix;
}

.float-grid-columns() {
    .col(@index) { // initial
        @item: ~".@{col-prefix-cls}-span-@{index}";
        .col((@index + 1), @item);
    }
    .col(@index, @list) when (@index =< @grid-columns) { // general
        @item: ~".@{col-prefix-cls}-span-@{index}";
        .col((@index + 1), ~"@{list}, @{item}");
    }
    .col(@index, @list) when (@index > @grid-columns) { // terminal
        @{list} {
            float: left;
            flex: 0 0 auto;
        }
    }
    .col(1); // kickstart it
}

.loop-grid-columns(@index) when (@index > 0) {
    .@{col-prefix-cls}-span-@{index} {
        display: block;
        width: percentage((@index / @grid-columns));
    }
    .@{col-prefix-cls}-push-@{index} {
        left: percentage((@index / @grid-columns));
    }
    .@{col-prefix-cls}-pull-@{index} {
        right: percentage((@index / @grid-columns));
    }
    .@{col-prefix-cls}-offset-@{index} {
        margin-left: percentage((@index / @grid-columns));
    }
    .@{col-prefix-cls}-order-@{index} {
        order: @index;
    }
    .loop-grid-columns((@index - 1));
}

.loop-grid-columns(@index) when (@index = 0) {
    .@{col-prefix-cls}-@{index} {
        display: none;
    }
    .@{col-prefix-cls}-push-@{index} {
        left: auto;
    }
    .@{col-prefix-cls}-pull-@{index} {
        right: auto;
    }
}

.make-grid() {
    .float-grid-columns();
    .loop-grid-columns(@grid-columns);
}