////////////////////////////// // Find width, in percentages, of the column span ////////////////////////////// @function column-span($span, $location, $columns: false, $gutter: false) { // Find the columns and gutters $columns: find-grid($columns); $gutter: find-gutter($gutter); // @debug $columns; // @debug $gutter; // Combine the columns and gutters $columns-and-gutters: column-sum($columns, $gutter); // @debug $columns-and-gutters; // Equal width columns are easy! Deal with them! @if type-of($columns) == 'number' or length($columns) == 1 { $span-and-gutters: $span + $gutter * ($span - 1); @return $span-and-gutters / $columns-and-gutters * 100%; } // Asymmetric lists are harder, so we're going to treat them as their own columns @else if type-of($columns) == 'list' or length($columns) > 1 { $span-and-gutters: 0; @if $location == 1 and $span >= 1 { @for $i from 1 through $span { $span-and-gutters: $span-and-gutters + nth($columns, $i) + $gutter; } } @else { $total: $location + $span - 1; @for $i from $location through $total { $span-and-gutters: $span-and-gutters + nth($columns, $i) + $gutter; } } $span-and-gutters: $span-and-gutters - $gutter; @return $span-and-gutters / $columns-and-gutters * 100%; } @else { @warn "Can't find a working set of columns! That's terrible!"; @return false; } } ////////////////////////////// // Find the total sum of the columns ////////////////////////////// @function column-sum($columns, $gutter) { @if type-of($columns) == 'number' or length($columns) == 1 { @return nth($columns, 1) + ((column-count(nth($columns, 1)) - 1) * nth($gutter, 1)); } @else if type-of($columns) == 'list' { $sum: 0; @each $column in $columns { $sum: $sum + nth($column, 1); } $sum: $sum + (column-count($columns) - 1) * nth($gutter, 1); @return $sum; } } ////////////////////////////// // Find the number of columns ////////////////////////////// @function column-count($columns) { @if type-of($columns) == 'number' { @return $columns; } @if type-of($columns) == 'list' { @if length($columns) == 1 { @return nth($columns, 1); } @else { @return length($columns); } } }