KNACSS/less/_03-grids.less

172 lines
3.1 KiB
Text
Raw Permalink Normal View History

2014-02-01 18:37:56 +01:00
/* ---------------------------------- */
/* ==Grids */
2014-02-01 18:37:56 +01: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/zxBMLW
2013-09-12 11:59:14 +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
2014-05-07 10:45:47 +02:00
// Usage with preprocessors : if you're using LESS, you can config grids variables :
// n = number of columns (default = 4) / g = gutter value (default = 1em)
// example : .grid-container { .grid(12, 10px); }
// ... or uneven grids :
// left = left ratio column (default = 2) / right = right ratio column (default = 1) / gutter (default = 1em)
// example : .grid-container { .uneven-grid(2, 1, 10px); }
2014-05-07 10:45:47 +02:00
// LESS mixins for *equal* columns grid container
// example : .grid-container { .grid(12, 10px); }
.grid(@number:@number, @gutter:@gutter) {
display: flex;
flex-direction: row;
flex-wrap: wrap;
margin-left: -@gutter;
& > * {
/* grid child can be any element */
flex: 0 0 auto;
width: (1/@number * 100) + 0%;
display: block; /* IE fix */
border-left: @gutter solid transparent;
background-clip: padding-box !important; /* no background on border */
}
& > .flexitem-double {
width: (2/@number * 100) + 0%;
}
& > .flexitem-first {
order: -1;
}
@media (min-width: (@small-screen + 1)) and (max-width: @medium-screen) {
& > * {
width: 33.3333%;
}
& > .flexitem-double {
width: 66.6666%;
}
}
@media (min-width: (@tiny-screen + 1)) and (max-width: @small-screen) {
& > * {
width: 50%;
}
& > .flexitem-double {
width: 100%;
}
}
@media (max-width: @tiny-screen) {
& > * {
width: 100%;
}
& > .flexitem-double {
width: 100%;
}
}
2014-05-03 11:08:29 +02:00
}
2014-05-07 10:45:47 +02:00
/* Examples : will be compiled in CSS */
2014-05-19 10:46:39 +02:00
.grid-2 {
.grid(2);
2013-09-12 11:59:14 +02:00
}
2014-05-07 10:45:47 +02:00
.grid-3 {
.grid(3);
2013-09-26 20:38:02 +02:00
}
2014-05-07 10:45:47 +02:00
.grid-4 {
.grid(4);
2014-05-07 10:45:47 +02:00
}
.grid-5 {
.grid(5);
2014-05-07 10:45:47 +02:00
}
.grid-6 {
.grid(6);
2014-05-07 10:45:47 +02:00
}
.grid-7 {
.grid(7);
2014-05-07 10:45:47 +02:00
}
.grid-8 {
.grid(8);
2014-05-07 10:45:47 +02:00
}
.grid-10 {
.grid(10);
2014-05-07 10:45:47 +02:00
}
.grid-12 {
.grid(12);
2014-05-07 10:45:47 +02:00
}
.grid-16 {
.grid(16);
2014-05-07 10:45:47 +02:00
}
2013-09-12 11:59:14 +02:00
// LESS mixins for *unequal* columns grid container
// example : .grid-container { .uneven-grid(2, 1, 10px); }
2014-05-07 10:45:47 +02:00
.uneven-grid(@left:@left, @right:@right, @gutter:@gutter) {
display: flex;
flex-direction: row;
flex-wrap: wrap;
margin-left: -@gutter;
2014-05-07 10:45:47 +02:00
& > * {
display: block; /* IE fix */
border-left: @gutter solid transparent;
background-clip: padding-box !important; /* no background on border */
}
& > *:nth-child(odd) {
width: (@left / (@left + @right)) * 100%;
}
& > *:nth-child(even) {
width: (@right / (@left + @right)) * 100%;
}
2014-05-07 10:45:47 +02:00
@media (max-width: @tiny-screen) {
& > *:nth-child(n) {
width: 100%;
}
}
2014-05-07 10:45:47 +02:00
}
2013-09-12 11:59:14 +02:00
2014-02-01 18:37:56 +01:00
/* Examples : will be compiled in CSS */
2014-02-01 18:37:56 +01:00
.grid-2-1 {
.uneven-grid(2,1);
2014-02-01 18:37:56 +01:00
}
2014-05-07 10:45:47 +02:00
.grid-1-2 {
.uneven-grid(1,2);
2014-02-01 18:37:56 +01:00
}
2014-05-07 10:45:47 +02:00
.grid-3-1 {
.uneven-grid(3,1);
2014-05-03 11:08:29 +02:00
}
2014-05-07 10:45:47 +02:00
.grid-1-3 {
.uneven-grid(1,3);
2014-05-03 11:08:29 +02:00
}
2014-05-07 10:45:47 +02:00
.grid-3-2 {
.uneven-grid(3,2);
2014-05-03 11:08:29 +02:00
}
2014-05-07 10:45:47 +02:00
.grid-2-3 {
.uneven-grid(2,3);
2014-02-01 18:37:56 +01:00
}
2014-05-07 10:45:47 +02:00
.grid-4-1 {
.uneven-grid(4,1);
2014-05-07 10:45:47 +02:00
}
.grid-1-4 {
.uneven-grid(1,4);
}