Improve grid and uneven-grid mixins in sass and less
This commit is contained in:
parent
139833e5aa
commit
78bb609da4
2 changed files with 38 additions and 18 deletions
|
@ -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) {
|
||||
.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) {
|
||||
&: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)';
|
||||
|
|
|
@ -43,14 +43,18 @@
|
|||
|
||||
// Sass mixins for *equal* columns grid container
|
||||
// example : .grid-perso { @include grid(12); }
|
||||
@mixin grid($number:$number,$gutter:$gutter) {
|
||||
margin-left: -$gutter;
|
||||
@mixin grid($number:$number,$newgutter:$gutter) {
|
||||
@if $newgutter != $gutter {
|
||||
margin-left: -$newgutter;
|
||||
}
|
||||
& > * {
|
||||
width: calc(100% * 1 / #{$number} - #{$gutter} - .01px);
|
||||
margin-left: $gutter;
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,22 +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) {
|
||||
margin-left: -$gutter;
|
||||
@mixin uneven-grid($left:$left, $right:$right, $newgutter:$gutter) {
|
||||
@if $newgutter != $gutter {
|
||||
margin-left: -$newgutter;
|
||||
}
|
||||
> * {
|
||||
margin-left: $gutter;
|
||||
@if $newgutter != $gutter {
|
||||
margin-left: $newgutter;
|
||||
}
|
||||
&:nth-child(odd) {
|
||||
$size: ($left / ($left + $right)) * 100%;
|
||||
width: calc(#{$size} - #{$gutter});
|
||||
width: calc(#{$size} - #{$newgutter});
|
||||
}
|
||||
&:nth-child(even) {
|
||||
$size: ($right / ($left + $right)) * 100%;
|
||||
width: calc(#{$size} - #{$gutter});
|
||||
width: calc(#{$size} - #{$newgutter});
|
||||
}
|
||||
}
|
||||
@media (max-width: $small-screen) {
|
||||
& > *:nth-child(n) {
|
||||
width: calc(100% - #{$gutter});
|
||||
width: calc(100% - #{$newgutter});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue