KNACSS/sass/_layout-grids.scss
2016-05-20 08:58:56 +02:00

165 lines
4.3 KiB
SCSS

/* ---------------------------------- */
/* ==Grid Layout (grillade) */
/* ---------------------------------- */
// Tuto : http://www.alsacreations.com/tuto/lire/1659-une-grille-responsive-avec-flexbox-et-LESS.html
// Demo : http://codepen.io/raphaelgoetter/pen/ZYjwEB
// Usage in vanilla CSS:
// - <div class="grid-4"> for an equal fourth columns grid container
// - <div class="grid-2-1"> for an uneven columns grid container
// Usage with preprocessors : if you're using Sass, you can config grids variables :
// n = number of columns (default = 4) / g = gutter value (default = 1em)
// example : .grid-perso { @include grid(12, 10px); }
// ... or uneven grids :
// left = left ratio column (default = 2) / right = right ratio column (default = 1)
// example : .grid-perso { @include uneven-grid(2, 1, 10px); }
/* grid container */
[class*="#{$kna-namespace}grid-"] {
display: flex;
flex-direction: row;
flex-wrap: wrap;
margin-left: -$grid-gutter;
}
/* grid childs */
[class*="#{$kna-namespace}grid-"] > * {
box-sizing: border-box;
flex: 0 0 auto;
width: calc(100% - #{$grid-gutter} - .01px);// @bugfix IE https://github.com/alsacreations/KNACSS/issues/133;
min-width: 0;
min-height: 0;
margin-left: $grid-gutter;
@include media('>tiny-screen', '<=small-screen') {
& {
width: calc(100% * 1 / 2 - #{$grid-gutter} - .01px);
}
&.flex-item-double {
width: calc(100% - #{$grid-gutter} - .01px);
}
}
}
// Sass mixins for *equal* columns grid container
// example : .grid-perso { @include grid(12); }
@mixin grid($grid-number:$grid-number,$newgutter:$grid-gutter) {
@if $newgutter != $grid-gutter {
margin-left: -$newgutter;
}
& > * {
width: calc(100% * 1 / #{$grid-number} - #{$newgutter} - .01px);
@if $newgutter != $grid-gutter {
margin-left: $newgutter;
}
}
& > .#{$kna-namespace}flex-item-double {
width: calc(100% * 2 / #{$grid-number} - #{$newgutter});
}
}
// Examples : will be compiled in CSS
@include media('>small-screen') {
@for $i from 2 through 12 {
[class*="#{$kna-namespace}grid-#{$i}"] {
@include grid(#{$i});
}
}
}
/* Responsive grid */
// example : .grid-4-small-2 will be 1 column (tiny) then 2 columns (small) then 4 columns
@include media('>tiny-screen', '<=small-screen') {
[class*="-small-4"] > * {
width: calc(100% * 1 / 4 - #{$grid-gutter} - .01px);
}
[class*="-small-4"] > .flex-item-double {
width: calc(100% * 1 / 2 - #{$grid-gutter} - .01px);
}
[class*="-small-3"] > * {
width: calc(100% * 1 / 3 - #{$grid-gutter} - .01px);
}
[class*="-small-3"] > .flex-item-double {
width: calc(100% * 2 / 3 - #{$grid-gutter} - .01px);
}
[class*="-small-2"] > * {
width: calc(100% * 1 / 2 - #{$grid-gutter} - .01px);
}
[class*="-small-2"] > .flex-item-double {
width: calc(100% - #{$grid-gutter} - .01px);
}
[class*="-small-1"] > * {
width: calc(100% - #{$grid-gutter} - .01px);
}
[class*="-small-1"] > .flex-item-double {
width: calc(100% - #{$grid-gutter} - .01px);
}
}
// Sass mixins for *unequal* columns grid container
// example : .grid-perso { @include uneven-grid(2, 1); }
@mixin uneven-grid($grid-left:$grid-left, $grid-right:$grid-right, $newgutter:$grid-gutter) {
@if $newgutter != $grid-gutter {
margin-left: -$newgutter;
}
> * {
@if $newgutter != $grid-gutter {
margin-left: $newgutter;
width: calc(100% - #{$newgutter});
}
}
@include media('>small-screen') {
& :nth-child(odd) {
$size: ($grid-left / ($grid-left + $grid-right)) * 100%;
width: calc(#{$size} - #{$newgutter});
}
& :nth-child(even) {
$size: ($grid-right / ($grid-left + $grid-right)) * 100%;
width: calc(#{$size} - #{$newgutter});
}
}
}
// Examples : will be compiled in CSS
.#{$kna-namespace}grid-2-1 {
@include uneven-grid(2,1);
}
.#{$kna-namespace}grid-1-2 {
@include uneven-grid(1,2);
}
.#{$kna-namespace}grid-3-1 {
@include uneven-grid(3,1);
}
.#{$kna-namespace}grid-1-3 {
@include uneven-grid(1,3);
}
.#{$kna-namespace}grid-3-2 {
@include uneven-grid(3,2);
}
.#{$kna-namespace}grid-2-3 {
@include uneven-grid(2,3);
}
.#{$kna-namespace}grid-4-1 {
@include uneven-grid(4,1);
}
.#{$kna-namespace}grid-1-4 {
@include uneven-grid(1,4);
}
.#{$kna-namespace}pull {
margin-right: auto;
}
.#{$kna-namespace}push {
margin-left: auto;
}