KNACSS/sass/_03-grids.scss

151 lines
3.4 KiB
SCSS
Raw Permalink Normal View History

2014-05-04 15:48:00 +02:00
/* ---------------------------------- */
/* ==Grids */
2014-05-04 15:48:00 +02:00
/* ---------------------------------- */
// WARNING : KNACSS grids are flexbox based and only supported by IE10+
// 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) / gutter (default = 1em)
// example : .grid-perso { @include uneven-grid(2, 1, 10px); }
[class*="#{$kna-namespace}grid-"] {
display: flex;
flex-direction: row;
flex-wrap: wrap;
2014-05-19 10:46:39 +02:00
margin-left: -$gutter;
}
[class*="#{$kna-namespace}grid-"] > * {
flex: 0 0 auto;
display: block; /* IE fix */
2015-06-26 14:04:16 +02:00
width: calc(100% * 1 / #{$number} - #{$gutter} - .01px);
2015-03-30 12:24:54 +02:00
margin-left: $gutter;
}
// Sass mixins for *equal* columns grid container
// example : .grid-perso { @include grid(12); }
2015-03-30 12:24:54 +02:00
@mixin grid($number:$number,$gutter:$gutter) {
& > * {
2015-06-26 14:04:16 +02:00
width: calc(100% * 1 / #{$number} - #{$gutter} - .01px);
2015-03-30 12:24:54 +02:00
}
& > .#{$kna-namespace}flex-item-double {
2015-03-30 12:24:54 +02:00
width: calc(100% * 2 / #{$number} - #{$gutter});
}
@media (min-width: ($tiny-screen + 1)) and (max-width: $small-screen) {
& > * {
2015-06-26 14:04:16 +02:00
width: calc(100% * 1 / 2 - #{$gutter} - .01px);
}
& > .#{$kna-namespace}flex-item-double {
2015-06-26 14:04:16 +02:00
width: calc(100% - #{$gutter} - .01px);
}
}
@media (max-width: $tiny-screen) {
& > * {
2015-06-26 14:04:16 +02:00
width: calc(100% - #{$gutter} - .01px);
}
& > .#{$kna-namespace}flex-item-double {
2015-06-26 14:04:16 +02:00
width: calc(100% - #{$gutter} - .01px);
}
}
2014-05-07 11:12:14 +02:00
}
// Examples : will be compiled in CSS
2014-05-07 11:12:14 +02:00
.#{$kna-namespace}grid-2 {
@include grid(2);
2014-05-07 11:12:14 +02:00
}
.#{$kna-namespace}grid-3 {
@include grid(3);
2014-05-07 11:12:14 +02:00
}
.#{$kna-namespace}grid-4 {
@include grid(4);
2014-05-07 11:12:14 +02:00
}
.#{$kna-namespace}grid-5 {
@include grid(5);
2014-05-07 11:12:14 +02:00
}
.#{$kna-namespace}grid-6 {
@include grid(6);
2014-05-07 11:12:14 +02:00
}
.#{$kna-namespace}grid-7 {
@include grid(7);
2014-05-07 11:12:14 +02:00
}
2014-05-04 15:48:00 +02:00
.#{$kna-namespace}grid-8 {
@include grid(8);
2014-05-07 11:12:14 +02:00
}
.#{$kna-namespace}grid-10 {
@include grid(10);
2014-05-07 11:12:14 +02:00
}
.#{$kna-namespace}grid-12 {
@include grid(12);
2014-05-07 11:12:14 +02:00
}
// LESS mixins for *unequal* columns grid container
// example : .grid-perso { @include uneven-grid(2, 1); }
2015-03-30 12:24:54 +02:00
@mixin uneven-grid($left:$left, $right:$right, $gutter:$gutter) {
& > *:nth-child(odd) {
2015-03-30 12:24:54 +02:00
$size: ($left / ($left + $right)) * 100%;
width: calc(#{$size} - #{$gutter});
}
& > *:nth-child(even) {
2015-03-30 12:24:54 +02:00
$size: ($right / ($left + $right)) * 100%;
width: calc(#{$size} - #{$gutter});
}
@media (max-width: $tiny-screen) {
& > *:nth-child(n) {
2015-03-30 12:24:54 +02:00
width: calc(100% - #{$gutter});
}
}
2014-05-04 15:48:00 +02:00
}
2014-05-07 11:12:14 +02:00
// Examples : will be compiled in CSS
2014-05-07 11:12:14 +02:00
.#{$kna-namespace}grid-2-1 {
@include uneven-grid(2,1);
2014-05-07 11:12:14 +02:00
}
.#{$kna-namespace}grid-1-2 {
@include uneven-grid(1,2);
2014-05-07 11:12:14 +02:00
}
.#{$kna-namespace}grid-3-1 {
@include uneven-grid(3,1);
2014-05-07 11:12:14 +02:00
}
.#{$kna-namespace}grid-1-3 {
@include uneven-grid(1,3);
2014-05-07 11:12:14 +02:00
}
.#{$kna-namespace}grid-3-2 {
@include uneven-grid(3,2);
2014-05-07 11:12:14 +02:00
}
.#{$kna-namespace}grid-2-3 {
@include uneven-grid(2,3);
2014-05-07 11:12:14 +02:00
}
.#{$kna-namespace}grid-4-1 {
@include uneven-grid(4,1);
2014-05-07 11:12:14 +02:00
}
.#{$kna-namespace}grid-1-4 {
@include uneven-grid(1,4);
}