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;
|
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
|
// LESS mixins for *equal* columns grid container
|
||||||
// example : .grid-perso { .grid(12); }
|
// example : .grid-perso { .grid(12); }
|
||||||
.grid(@number:@number, @gutter:@gutter) {
|
.grid(@number:@number, @gutter:@gutter) {
|
||||||
|
.check-new-margin(@gutter, -1);
|
||||||
& > * {
|
& > * {
|
||||||
width: ~'calc(100% * 1 / @{number} - @{gutter} - .01px)';
|
width: ~'calc(100% * 1 / @{number} - @{gutter} - .01px)';
|
||||||
|
.check-new-margin(@gutter, 1);
|
||||||
}
|
}
|
||||||
& > .@{kna-namespace}flex-item-double {
|
& > .@{kna-namespace}flex-item-double {
|
||||||
width: ~'calc(100% * 2 / @{number} - @{gutter} - .01px)';
|
width: ~'calc(100% * 2 / @{number} - @{gutter} - .01px)';
|
||||||
|
@ -130,14 +137,19 @@
|
||||||
// LESS mixins for *unequal* columns grid container
|
// LESS mixins for *unequal* columns grid container
|
||||||
// example : .grid-perso { .uneven-grid(2, 1); }
|
// example : .grid-perso { .uneven-grid(2, 1); }
|
||||||
.uneven-grid(@left:@left, @right:@right, @gutter:@gutter) {
|
.uneven-grid(@left:@left, @right:@right, @gutter:@gutter) {
|
||||||
& > *:nth-child(odd) {
|
.check-new-margin(@gutter, -1);
|
||||||
@size: (@left / (@left + @right)) * 100%;
|
& > * {
|
||||||
width: ~'calc(@{size} - @{gutter} - .01px)';
|
.check-new-margin(@gutter, 1);
|
||||||
}
|
&:nth-child(odd) {
|
||||||
& > *:nth-child(even) {
|
@size: (@left / (@left + @right)) * 100%;
|
||||||
@size: (@right / (@left + @right)) * 100%;
|
width: ~'calc(@{size} - @{gutter} - .01px)';
|
||||||
width: ~'calc(@{size} - @{gutter} - .01px)';
|
}
|
||||||
|
&:nth-child(even) {
|
||||||
|
@size: (@right / (@left + @right)) * 100%;
|
||||||
|
width: ~'calc(@{size} - @{gutter} - .01px)';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: @small-screen) {
|
@media (max-width: @small-screen) {
|
||||||
& > *:nth-child(n) {
|
& > *:nth-child(n) {
|
||||||
width: ~'calc(100% - @{gutter} - .01px)';
|
width: ~'calc(100% - @{gutter} - .01px)';
|
||||||
|
|
|
@ -43,14 +43,18 @@
|
||||||
|
|
||||||
// Sass mixins for *equal* columns grid container
|
// Sass mixins for *equal* columns grid container
|
||||||
// example : .grid-perso { @include grid(12); }
|
// example : .grid-perso { @include grid(12); }
|
||||||
@mixin grid($number:$number,$gutter:$gutter) {
|
@mixin grid($number:$number,$newgutter:$gutter) {
|
||||||
margin-left: -$gutter;
|
@if $newgutter != $gutter {
|
||||||
|
margin-left: -$newgutter;
|
||||||
|
}
|
||||||
& > * {
|
& > * {
|
||||||
width: calc(100% * 1 / #{$number} - #{$gutter} - .01px);
|
width: calc(100% * 1 / #{$number} - #{$newgutter} - .01px);
|
||||||
margin-left: $gutter;
|
@if $newgutter != $gutter {
|
||||||
|
margin-left: $newgutter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
& > .#{$kna-namespace}flex-item-double {
|
& > .#{$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
|
// Sass mixins for *unequal* columns grid container
|
||||||
// example : .grid-perso { @include uneven-grid(2, 1); }
|
// example : .grid-perso { @include uneven-grid(2, 1); }
|
||||||
@mixin uneven-grid($left:$left, $right:$right, $gutter:$gutter) {
|
@mixin uneven-grid($left:$left, $right:$right, $newgutter:$gutter) {
|
||||||
margin-left: -$gutter;
|
@if $newgutter != $gutter {
|
||||||
|
margin-left: -$newgutter;
|
||||||
|
}
|
||||||
> * {
|
> * {
|
||||||
margin-left: $gutter;
|
@if $newgutter != $gutter {
|
||||||
|
margin-left: $newgutter;
|
||||||
|
}
|
||||||
&:nth-child(odd) {
|
&:nth-child(odd) {
|
||||||
$size: ($left / ($left + $right)) * 100%;
|
$size: ($left / ($left + $right)) * 100%;
|
||||||
width: calc(#{$size} - #{$gutter});
|
width: calc(#{$size} - #{$newgutter});
|
||||||
}
|
}
|
||||||
&:nth-child(even) {
|
&:nth-child(even) {
|
||||||
$size: ($right / ($left + $right)) * 100%;
|
$size: ($right / ($left + $right)) * 100%;
|
||||||
width: calc(#{$size} - #{$gutter});
|
width: calc(#{$size} - #{$newgutter});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@media (max-width: $small-screen) {
|
@media (max-width: $small-screen) {
|
||||||
& > *:nth-child(n) {
|
& > *:nth-child(n) {
|
||||||
width: calc(100% - #{$gutter});
|
width: calc(100% - #{$newgutter});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue