KNACSS/sass/_03-grids.scss

309 lines
5.2 KiB
SCSS
Raw Normal View History

2014-05-04 15:48:00 +02:00
/* ---------------------------------- */
/* ==Grids */
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
// 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 :
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); }
/* grid container */
[class*="#{$kna-namespace}grid-"] {
2015-07-01 13:47:48 +02:00
display: flex;
flex-direction: row;
flex-wrap: wrap;
margin-left: -$gutter;
/* inline-block fallback for IE9 generation */
letter-spacing: -0.31em;
text-rendering: optimizespeed;
}
/* grid childs */
[class*="#{$kna-namespace}grid-"] > * {
2015-07-01 13:47:48 +02:00
flex: 0 0 auto;
width: calc(100% * 1 / # {
$number
}
- # {
$gutter
}
- .01px);
2015-07-01 13:47:48 +02:00
margin-left: $gutter;
/* inline-block fallback for IE9 generation */
display: inline-block;
vertical-align: top;
letter-spacing: normal;
text-rendering: auto;
}
// Sass mixins for *equal* columns grid container
// example : .grid-perso { @include grid(12); }
@mixin grid($number:$number,
$gutter:$gutter) {
2015-07-05 16:56:19 +02:00
& > * {
width: calc(100% * 1 / # {
$number
}
- # {
$gutter
}
- .01px);
}
& > .# {
$kna-namespace
2015-07-01 13:47:48 +02:00
}
flex-item-double {
width: calc(100% * 2 / # {
$number
}
- # {
$gutter
}
);
2015-07-01 13:47:48 +02:00
}
2014-05-07 11:12:14 +02:00
}
// Examples : will be compiled in CSS
2015-07-05 16:56:19 +02:00
[class*="#{$kna-namespace}grid-2"] {
2015-07-01 13:47:48 +02:00
@include grid(2);
2014-05-07 11:12:14 +02:00
}
2015-07-05 16:56:19 +02:00
[class*="#{$kna-namespace}grid-3"] {
2015-07-01 13:47:48 +02:00
@include grid(3);
2014-05-07 11:12:14 +02:00
}
2015-07-05 16:56:19 +02:00
[class*="#{$kna-namespace}grid-4"] {
2015-07-01 13:47:48 +02:00
@include grid(4);
2014-05-07 11:12:14 +02:00
}
2015-07-05 16:56:19 +02:00
[class*="#{$kna-namespace}grid-5"] {
2015-07-01 13:47:48 +02:00
@include grid(5);
2014-05-07 11:12:14 +02:00
}
2015-07-05 16:56:19 +02:00
[class*="#{$kna-namespace}grid-6"] {
2015-07-01 13:47:48 +02:00
@include grid(6);
2014-05-07 11:12:14 +02:00
}
2015-07-05 16:56:19 +02:00
[class*="#{$kna-namespace}grid-7"] {
2015-07-01 13:47:48 +02:00
@include grid(7);
2014-05-07 11:12:14 +02:00
}
2014-05-04 15:48:00 +02:00
2015-07-05 16:56:19 +02:00
[class*="#{$kna-namespace}grid-8"] {
2015-07-01 13:47:48 +02:00
@include grid(8);
2014-05-07 11:12:14 +02:00
}
2015-07-05 16:56:19 +02:00
[class*="#{$kna-namespace}grid-10"] {
2015-07-01 13:47:48 +02:00
@include grid(10);
2014-05-07 11:12:14 +02:00
}
2015-07-05 16:56:19 +02:00
[class*="#{$kna-namespace}grid-12"] {
2015-07-01 13:47:48 +02:00
@include grid(12);
2014-05-07 11:12:14 +02:00
}
2015-07-05 16:56:19 +02:00
/* Responsive grid */
2015-07-05 16:56:19 +02:00
// "small-2" = 2 columns when small screen
// example : .grid-4-small-2 will be 4 then 2 columns
@media (max-width: $small-screen) {
[class*="-small-4"] > * {
width: calc(100% * 1 / 4 - # {
$gutter
}
- .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-small-4"] > .flex-item-double {
width: calc(100% * 1 / 2 - # {
$gutter
}
- .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-small-3"] > * {
width: calc(100% * 1 / 3 - # {
$gutter
}
- .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-small-3"] > .flex-item-double {
width: calc(100% * 2 / 3 - # {
$gutter
}
- .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-small-2"] > * {
width: calc(100% * 1 / 2 - # {
$gutter
}
- .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-small-2"] > .flex-item-double {
width: calc(100% - # {
$gutter
}
- .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-small-1"] > * {
width: calc(100% - # {
$gutter
}
- .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-small-1"] > .flex-item-double {
width: calc(100% - # {
$gutter
}
- .01px);
2015-07-05 16:56:19 +02:00
}
}
2015-07-05 16:56:19 +02:00
// "tiny-1" = 1 column when tiny screen
// example : .grid-4-small-2-tiny-1 will be 4 then 2 columns then 1 column
@media (max-width: $tiny-screen) {
[class*="-tiny-2"] > * {
width: calc(100% * 1 / 2 - # {
$gutter
}
- .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-tiny-2"] > .flex-item-double {
width: calc(100% - # {
$gutter
}
- .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-tiny-1"] > * {
width: calc(100% - # {
$gutter
}
- .01px);
2015-07-05 16:56:19 +02:00
}
[class*="-tiny-1"] > .flex-item-double {
width: calc(100% - # {
$gutter
}
- .01px);
2015-07-05 16:56:19 +02:00
}
}
// LESS mixins for *unequal* columns grid container
// example : .grid-perso { @include uneven-grid(2, 1); }
@mixin uneven-grid($left:$left,
$right:$right,
$gutter:$gutter) {
& > *: nth-child(odd) {
2015-07-01 13:47:48 +02:00
$size: ($left / ($left + $right)) * 100%;
width: calc(# {
$size
}
- # {
$gutter
}
);
2015-07-01 13:47:48 +02:00
}
& > *:nth-child(even) {
$size: ($right / ($left + $right)) * 100%;
width: calc(# {
$size
}
- # {
$gutter
}
);
2015-07-01 13:47:48 +02:00
}
2015-08-06 15:41:56 +02:00
@media (max-width: $small-screen) {
& > *: nth-child(n) {
width: calc(100% - # {
$gutter
}
);
2015-07-01 13:47:48 +02:00
}
}
2014-05-04 15:48:00 +02:00
}
2014-05-07 11:12:14 +02:00
// Examples : will be compiled in CSS
.# {
$kna-namespace
}
grid-2-1 {
@include uneven-grid(2, 1);
}
2014-05-07 11:12:14 +02:00
.# {
$kna-namespace
2014-05-07 11:12:14 +02:00
}
grid-1-2 {
@include uneven-grid(1, 2);
2014-05-07 11:12:14 +02:00
}
.# {
$kna-namespace
2014-05-07 11:12:14 +02:00
}
grid-3-1 {
@include uneven-grid(3, 1);
2014-05-07 11:12:14 +02:00
}
.# {
$kna-namespace
2014-05-07 11:12:14 +02:00
}
grid-1-3 {
@include uneven-grid(1, 3);
2014-05-07 11:12:14 +02:00
}
.# {
$kna-namespace
2014-05-07 11:12:14 +02:00
}
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;
}