diff --git a/less/_03-grids.less b/less/_03-grids.less index e43e4a9..bd99e45 100644 --- a/less/_03-grids.less +++ b/less/_03-grids.less @@ -41,11 +41,18 @@ letter-spacing: normal; } +// LESS mixin for custom grid container +.check-new-margin(@newgutter, @multiplier) when not (@newgutter = @gutter) { + margin-left: @newgutter * @multiplier; +} + // LESS mixins for *equal* columns grid container // example : .grid-perso { .grid(12); } .grid(@number:@number, @gutter:@gutter) { + .check-new-margin(@gutter, -1); & > * { width: ~'calc(100% * 1 / @{number} - @{gutter} - .01px)'; + .check-new-margin(@gutter, 1); } & > .@{kna-namespace}flex-item-double { width: ~'calc(100% * 2 / @{number} - @{gutter} - .01px)'; @@ -130,14 +137,19 @@ // LESS mixins for *unequal* columns grid container // example : .grid-perso { .uneven-grid(2, 1); } .uneven-grid(@left:@left, @right:@right, @gutter:@gutter) { - & > *:nth-child(odd) { - @size: (@left / (@left + @right)) * 100%; - width: ~'calc(@{size} - @{gutter} - .01px)'; - } - & > *:nth-child(even) { - @size: (@right / (@left + @right)) * 100%; - width: ~'calc(@{size} - @{gutter} - .01px)'; + .check-new-margin(@gutter, -1); + & > * { + .check-new-margin(@gutter, 1); + &:nth-child(odd) { + @size: (@left / (@left + @right)) * 100%; + width: ~'calc(@{size} - @{gutter} - .01px)'; + } + &:nth-child(even) { + @size: (@right / (@left + @right)) * 100%; + width: ~'calc(@{size} - @{gutter} - .01px)'; + } } + @media (max-width: @small-screen) { & > *:nth-child(n) { width: ~'calc(100% - @{gutter} - .01px)'; diff --git a/sass/_03-grids.scss b/sass/_03-grids.scss index dc6321f..a85e19d 100644 --- a/sass/_03-grids.scss +++ b/sass/_03-grids.scss @@ -43,12 +43,18 @@ // Sass mixins for *equal* columns grid container // example : .grid-perso { @include grid(12); } -@mixin grid($number:$number,$gutter:$gutter) { +@mixin grid($number:$number,$newgutter:$gutter) { + @if $newgutter != $gutter { + margin-left: -$newgutter; + } & > * { - width: calc(100% * 1 / #{$number} - #{$gutter} - .01px); + width: calc(100% * 1 / #{$number} - #{$newgutter} - .01px); + @if $newgutter != $gutter { + margin-left: $newgutter; + } } & > .#{$kna-namespace}flex-item-double { - width: calc(100% * 2 / #{$number} - #{$gutter}); + width: calc(100% * 2 / #{$number} - #{$newgutter}); } } @@ -138,18 +144,26 @@ // Sass mixins for *unequal* columns grid container // example : .grid-perso { @include uneven-grid(2, 1); } -@mixin uneven-grid($left:$left, $right:$right, $gutter:$gutter) { - & > *:nth-child(odd) { - $size: ($left / ($left + $right)) * 100%; - width: calc(#{$size} - #{$gutter}); +@mixin uneven-grid($left:$left, $right:$right, $newgutter:$gutter) { + @if $newgutter != $gutter { + margin-left: -$newgutter; } - & > *:nth-child(even) { - $size: ($right / ($left + $right)) * 100%; - width: calc(#{$size} - #{$gutter}); + > * { + @if $newgutter != $gutter { + margin-left: $newgutter; + } + &:nth-child(odd) { + $size: ($left / ($left + $right)) * 100%; + width: calc(#{$size} - #{$newgutter}); + } + &:nth-child(even) { + $size: ($right / ($left + $right)) * 100%; + width: calc(#{$size} - #{$newgutter}); + } } @media (max-width: $small-screen) { & > *:nth-child(n) { - width: calc(100% - #{$gutter}); + width: calc(100% - #{$newgutter}); } } }