KNACSS/sass/_layout-grids.scss

166 lines
4.3 KiB
SCSS
Raw Normal View History

2014-05-04 15:48:00 +02:00
/* ---------------------------------- */
2016-05-20 08:58:56 +02:00
/* ==Grid Layout (grillade) */
2014-05-04 15:48:00 +02:00
/* ---------------------------------- */
// Tuto : http://www.alsacreations.com/tuto/lire/1659-une-grille-responsive-avec-flexbox-et-LESS.html
// Demo : http://codepen.io/raphaelgoetter/pen/ZYjwEB
2015-08-27 11:04:01 +02:00
// 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
2015-08-27 11:04:01 +02:00
// 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 :
2015-07-05 16:56:19 +02:00
// left = left ratio column (default = 2) / right = right ratio column (default = 1)
// example : .grid-perso { @include uneven-grid(2, 1, 10px); }
2015-08-27 11:04:01 +02:00
/* grid container */
[class*="#{$kna-namespace}grid-"] {
2015-07-01 13:47:48 +02:00
display: flex;
flex-direction: row;
flex-wrap: wrap;
2016-05-16 17:20:28 +02:00
margin-left: -$grid-gutter;
}
2015-08-27 11:04:01 +02:00
/* grid childs */
[class*="#{$kna-namespace}grid-"] > * {
2015-12-24 09:18:58 +01:00
box-sizing: border-box;
2015-07-01 13:47:48 +02:00
flex: 0 0 auto;
2016-05-16 17:20:28 +02:00
width: calc(100% - #{$grid-gutter} - .01px);// @bugfix IE https://github.com/alsacreations/KNACSS/issues/133;
min-width: 0;
2016-05-16 15:45:14 +02:00
min-height: 0;
2016-05-16 17:20:28 +02:00
margin-left: $grid-gutter;
2016-05-16 15:45:14 +02:00
@include media('>tiny-screen', '<=small-screen') {
& {
2016-05-16 17:20:28 +02:00
width: calc(100% * 1 / 2 - #{$grid-gutter} - .01px);
2016-05-16 15:45:14 +02:00
}
&.grid-item-double {
2016-05-16 17:20:28 +02:00
width: calc(100% - #{$grid-gutter} - .01px);
2016-05-16 15:45:14 +02:00
}
}
}
// Sass mixins for *equal* columns grid container
// example : .grid-perso { @include grid(12); }
2016-05-16 17:20:28 +02:00
@mixin grid($grid-number:$grid-number,$newgutter:$grid-gutter) {
@if $newgutter != $grid-gutter {
margin-left: -$newgutter;
}
2015-07-05 16:56:19 +02:00
& > * {
2016-05-16 17:20:28 +02:00
width: calc(100% * 1 / #{$grid-number} - #{$newgutter} - .01px);
@if $newgutter != $grid-gutter {
margin-left: $newgutter;
}
2015-07-01 13:47:48 +02:00
}
& > .#{$kna-namespace}grid-item-double {
2016-05-16 17:20:28 +02:00
width: calc(100% * 2 / #{$grid-number} - #{$newgutter});
2015-07-01 13:47:48 +02:00
}
2014-05-07 11:12:14 +02:00
}
// Examples : will be compiled in CSS
2016-05-16 15:45:14 +02:00
@include media('>small-screen') {
@for $i from 2 through 12 {
[class*="#{$kna-namespace}grid-#{$i}"] {
@include grid(#{$i});
}
}
2014-05-07 11:12:14 +02:00
}
2015-08-27 11:04:01 +02:00
/* Responsive grid */
2016-05-16 15:45:14 +02:00
// example : .grid-4-small-2 will be 1 column (tiny) then 2 columns (small) then 4 columns
@include media('>tiny-screen', '<=small-screen') {
2015-07-05 16:56:19 +02:00
[class*="-small-4"] > * {
2016-05-16 17:20:28 +02:00
width: calc(100% * 1 / 4 - #{$grid-gutter} - .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-small-4"] > .grid-item-double {
2016-05-16 17:20:28 +02:00
width: calc(100% * 1 / 2 - #{$grid-gutter} - .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-small-3"] > * {
2016-05-16 17:20:28 +02:00
width: calc(100% * 1 / 3 - #{$grid-gutter} - .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-small-3"] > .grid-item-double {
2016-05-16 17:20:28 +02:00
width: calc(100% * 2 / 3 - #{$grid-gutter} - .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-small-2"] > * {
2016-05-16 17:20:28 +02:00
width: calc(100% * 1 / 2 - #{$grid-gutter} - .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-small-2"] > .grid-item-double {
2016-05-16 17:20:28 +02:00
width: calc(100% - #{$grid-gutter} - .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-small-1"] > * {
2016-05-16 17:20:28 +02:00
width: calc(100% - #{$grid-gutter} - .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-small-1"] > .grid-item-double {
2016-05-16 17:20:28 +02:00
width: calc(100% - #{$grid-gutter} - .01px);
2015-07-05 16:56:19 +02:00
}
}
2016-05-16 15:45:14 +02:00
2015-07-05 16:56:19 +02:00
2015-11-19 04:52:38 +01:00
// Sass mixins for *unequal* columns grid container
// example : .grid-perso { @include uneven-grid(2, 1); }
2016-05-16 17:20:28 +02:00
@mixin uneven-grid($grid-left:$grid-left, $grid-right:$grid-right, $newgutter:$grid-gutter) {
@if $newgutter != $grid-gutter {
margin-left: -$newgutter;
}
2016-02-13 23:16:33 +01:00
> * {
2016-05-16 17:20:28 +02:00
@if $newgutter != $grid-gutter {
margin-left: $newgutter;
2016-05-16 15:45:14 +02:00
width: calc(100% - #{$newgutter});
}
2016-05-16 15:45:14 +02:00
}
@include media('>small-screen') {
& :nth-child(odd) {
2016-05-16 17:20:28 +02:00
$size: ($grid-left / ($grid-left + $grid-right)) * 100%;
width: calc(#{$size} - #{$newgutter});
2016-02-13 23:16:33 +01:00
}
2016-05-16 15:45:14 +02:00
& :nth-child(even) {
2016-05-16 17:20:28 +02:00
$size: ($grid-right / ($grid-left + $grid-right)) * 100%;
width: calc(#{$size} - #{$newgutter});
2016-02-13 23:16:33 +01:00
}
2015-07-01 13:47:48 +02:00
}
2014-05-04 15:48:00 +02:00
}
2014-05-07 11:12:14 +02:00
2015-08-27 11:04:01 +02:00
// Examples : will be compiled in CSS
2014-05-07 11:12:14 +02:00
2015-08-27 11:04:01 +02:00
.#{$kna-namespace}grid-2-1 {
@include uneven-grid(2,1);
}
2015-08-27 11:04:01 +02:00
.#{$kna-namespace}grid-1-2 {
@include uneven-grid(1,2);
}
2015-08-27 11:04:01 +02:00
.#{$kna-namespace}grid-3-1 {
@include uneven-grid(3,1);
}
2015-08-27 11:04:01 +02:00
.#{$kna-namespace}grid-1-3 {
@include uneven-grid(1,3);
}
2015-08-27 11:04:01 +02:00
.#{$kna-namespace}grid-3-2 {
@include uneven-grid(3,2);
}
2015-08-27 11:04:01 +02:00
.#{$kna-namespace}grid-2-3 {
@include uneven-grid(2,3);
}
2015-08-27 11:04:01 +02:00
.#{$kna-namespace}grid-4-1 {
@include uneven-grid(4,1);
}
2015-08-27 11:04:01 +02:00
.#{$kna-namespace}grid-1-4 {
@include uneven-grid(1,4);
}
2015-08-27 11:04:01 +02:00
.#{$kna-namespace}pull {
margin-right: auto;
}
2015-08-27 11:04:01 +02:00
.#{$kna-namespace}push {
margin-left: auto;
2015-11-19 04:52:38 +01:00
}