Skip to content

Instantly share code, notes, and snippets.

@stephen-james
Created September 9, 2013 09:54
Show Gist options
  • Save stephen-james/6493651 to your computer and use it in GitHub Desktop.
Save stephen-james/6493651 to your computer and use it in GitHub Desktop.
flexbox.less provides universal support for 2009/2011 draft and standard versions of the flexbox specification.
// flexbox.less
// https://gist.github.com/stephen-james/6493651
.flexbox(@inline : false) when (@inline)
{
// support the 2009 Draft
display : -webkit-inline-box;
display : -moz-inline-box;
display : inline-box;
// support the 2011 Draft
display : -ms-inline-flexbox;
display : inline-flexbox;
// support current (as at 2013)
display : -webkit-inline-flex;
display : inline-flex;
}
.flexbox(@inline : false) when (@inline = false)
{
// support the 2009 Draft
display : -webkit-box;
display : -moz-box;
display : box;
// support the 2011 Draft
display : -ms-flexbox;
display : flexbox;
// support current (as at 2013)
display : -webkit-flex;
display : -webkit-flex;
display : flex;
}
.flexbox-align-items(@alignment) when (@alignment = center), (@alignment = baseline), (@alignment = stretch)
{
// support the 2009 Draft
-webkit-box-align : @alignment;
-moz-box-align : @alignment;
box-align : @alignment;
// support the 2011 Draft
-ms-flex-align : @alignment;
// support current (as at 2013)
-webkit-align-items : @alignment;
-moz-align-items : @alignment;
-ms-align-items : @alignment;
align-items : @alignment;
}
.flexbox-align-items(@alignment) when (@alignment = start), (@alignment = flex-start)
{
// support the 2009 Draft
-webkit-box-align : start;
-moz-box-align : start;
box-align : start;
// support the 2011 Draft
-ms-flex-align : start;
// support current (as at 2013)
-webkit-align-items : flex-start;
-moz-align-items : flex-start;
-ms-align-items : flex-start;
align-items : flex-start;
}
.flexbox-align-items(@alignment) when (@alignment = end), (@alignment = flex-end)
{
// support the 2009 Draft
-webkit-box-align : end;
-moz-box-align : end;
box-align : end;
// support the 2011 Draft
-ms-flex-align : end;
// support current (as at 2013)
-webkit-align-items : flex-end;
-moz-align-items : flex-end;
-ms-align-items : flex-end;
align-items : flex-end;
}
.flexbox-justify-content(@packmethod) when (@packmethod = center)
{
// support the 2009 Draft
-webkit-box-pack: center;
-moz-box-pack: center;
box-pack: center;
// support the 2011 Draft
-ms-flex-pack: center;
// support current (as at 2013)
-webkit-justify-content: center;
-moz-justify-content : center;
-ms-justify-content : center;
justify-content: center;
}
.flexbox-justify-content(@packmethod) when (@packmethod = start), (@packmethod = flex-start)
{
// support the 2009 Draft
-webkit-box-pack: start;
-moz-box-pack: start;
box-pack: start;
// support the 2011 Draft
-ms-flex-pack: start;
// support current (as at 2013)
-webkit-justify-content: flex-start;
-moz-justify-content : flex-start;
-ms-justify-content : flex-start;
justify-content: flex-start;
}
.flexbox-justify-content(@packmethod) when (@packmethod = end), (@packmethod = flex-end)
{
// support the 2009 Draft
-webkit-box-pack: end;
-moz-box-pack: end;
box-pack: end;
// support the 2011 Draft
-ms-flex-pack: end;
// support current (as at 2013)
-webkit-justify-content: flex-end;
-moz-justify-content : flex-end;
-ms-justify-content : flex-end;
justify-content: flex-end;
}
.flexbox-justify-content(@packmethod) when (@packmethod = justify), (@packmethod = space-between)
{
// support the 2009 Draft
-webkit-box-pack: justify;
-moz-box-pack: justify;
box-pack: justify;
// support the 2011 Draft
-ms-flex-pack: justify;
// support current (as at 2013)
-webkit-justify-content: space-between;
-moz-justify-content : space-between;
-ms-justify-content : space-between;
justify-content: space-between;
}
.flexbox-justify-content(@packmethod) when (@packmethod = distribute), (@packmethod = space-around)
{
// support the 2009 Draft
-webkit-box-pack : distribute;
-moz-box-pack : distribute;
box-pack : distribute;
// support the 2011 Draft
-ms-flex-pack : distribute;
// support current (as at 2013)
-webkit-justify-content : space-around;
-moz-justify-content : space-around;
-ms-justify-content : space-around;
justify-content : space-around;
}
.flexbox-align-self(@alignmethod) when (@alignmethod = auto), (@alignmethod = center), (@alignmethod = baseline), (@alignmethod = stretch)
{
// not supported in the 2009 Draft
// support the 2011 Draft
-ms-flex-item-align : @alignmethod;
// support current (as at 2013)
-webkit-align-self : @alignmethod;
-moz-align-self : @alignmethod;
-ms-align-self : @alignmethod;
align-self : @alignmethod;
}
.flexbox-align-self(@alignmethod) when (@alignmethod = start), (@alignmethod = flex-start)
{
// not supported in the 2009 Draft
// support the 2011 Draft
-ms-flex-item-align : start;
// support current (as at 2013)
-webkit-align-self : flex-start;
-moz-align-self : flex-start;
-ms-align-self : flex-start;
align-self : flex-start;
}
.flexbox-align-self(@alignmethod) when (@alignmethod = end), (@alignmethod = flex-end)
{
// not supported in the 2009 Draft
// support the 2011 Draft
-ms-flex-item-align : end;
// support current (as at 2013)
-webkit-align-self : flex-end;
-moz-align-self : flex-end;
-ms-align-self : flex-end;
align-self : flex-end;
}
.flexbox-align-content(@alignmethod) when (@alignmethod = center), (@alignmethod = stretch)
{
// not supported in the 2009 Draft
// support the 2011 Draft
-ms-flex-line-pack : @alignmethod;
// support current (as at 2013)
-webkit-align-content : @alignmethod;
-moz-align-content : @alignmethod;
-ms-align-content : @alignmethod;
align-content : @alignmethod;
}
.flexbox-align-content(@alignmethod) when (@alignmethod = start), (@alignmethod = flex-start)
{
// not supported in the 2009 Draft
// support the 2011 Draft
-ms-flex-line-pack : start;
// support current (as at 2013)
-webkit-align-content : flex-start;
-moz-align-content : flex-start;
-ms-align-content : flex-start;
align-content : flex-start;
}
.flexbox-align-content(@alignmethod) when (@alignmethod = end), (@alignmethod = flex-end)
{
// not supported in the 2009 Draft
// support the 2011 Draft
-ms-flex-line-pack : end;
// support current (as at 2013)
-webkit-align-content : flex-end;
-moz-align-content : flex-end;
-ms-align-content : flex-end;
align-content : flex-end;
}
.flexbox-align-content(@alignmethod) when (@alignmethod = justify), (@alignmethod = space-between)
{
// not supported in the 2009 Draft
// support the 2011 Draft
-ms-flex-line-pack : justify;
// support current (as at 2013)
-webkit-align-content : space-between;
-moz-align-content : space-between;
-ms-align-content : space-between;
align-content : space-between;
}
.flexbox-align-content(@alignmethod) when (@alignmethod = distribute), (@alignmethod = space-around)
{
// not supported in the 2009 Draft
// support the 2011 Draft
-ms-flex-line-pack : distribute;
// support current (as at 2013)
-webkit-align-content : space-around;
-moz-align-content : space-around;
-ms-align-content : space-around;
align-content : space-around;
}
.flexbox-order(@number)
{
// support the 2009 Draft
-webkit-box-ordinal-group : @number;
-moz-box-ordinal-group : @number;
box-ordinal-group : @number;
// support the 2011 Draft
-ms-flex-order : @number;
// support current (as at 2013)
-webkit-order : @number;
-moz-order : @number;
-ms-order : @number;
order : @number;
}
.flexbox-flex(@grow : 0, @shrink : 1, @basis : auto)
{
// support the 2009 Draft
-webkit-box-flex : @grow;
-moz-box-flex : @grow;
box-flex : @grow;
// support the 2011 Draft
-ms-flex : @grow;
// support current (as at 2013)
-webkit-flex : @grow @shrink @basis;
-moz-flex : @grow @shrink @basis;
-ms-flex : @grow @shrink @basis;
flex : @grow @shrink @basis;
}
.flexbox-direction(@direction) when (@direction = row)
{
// support the 2009 Draft
-webkit-box-orient : horizontal;
-moz-box-orient : horizontal;
box-orient : horizontal;
-webkit-box-direction : normal;
-moz-box-direction : normal;
box-direction : normal;
// support the 2011 Draft
-ms-flex-direction : row;
// support current (as at 2013)
-webkit-flex-direction : row;
-moz-flex-direction : row;
-ms-flex-direction : row;
flex-direction : row;
}
.flexbox-direction(@direction) when (@direction = row-reverse)
{
// support the 2009 Draft
-webkit-box-orient : horizontal;
-moz-box-orient : horizontal;
box-orient : horizontal;
-webkit-box-direction : reverse;
-moz-box-direction : reverse;
box-direction : reverse;
// support the 2011 Draft
-ms-flex-direction : row-reverse;
// support current (as at 2013)
-webkit-flex-direction : row-reverse;
-moz-flex-direction : row-reverse;
-ms-flex-direction : row-reverse;
flex-direction : row-reverse;
}
.flexbox-direction(@direction) when (@direction = vertical), (@direction = column)
{
// support the 2009 Draft
-webkit-box-orient : vertical;
-moz-box-orient : vertical;
box-orient : vertical;
-webkit-box-direction : normal;
-moz-box-direction : normal;
box-direction : normal;
// support the 2011 Draft
-ms-flex-direction : column;
// support current (as at 2013)
-webkit-flex-direction : column;
-moz-flex-direction : column;
-ms-flex-direction : column;
flex-direction : column;
}
.flexbox-direction(@direction) when (@direction = column-reverse)
{
// support the 2009 Draft
-webkit-box-orient : vertical;
-moz-box-orient : vertical;
box-orient : vertical;
-webkit-box-direction : reverse;
-moz-box-direction : reverse;
box-direction : reverse;
// support the 2011 Draft
-ms-flex-direction : column-reverse;
// support current (as at 2013)
-webkit-flex-direction : column-reverse;
-moz-flex-direction : column-reverse;
-ms-flex-direction : column-reverse;
flex-direction : column-reverse;
}
.flexbox-wrap(@wrapping) when (@wrapping = single), (@wrapping = nowrap)
{
// support the 2009 Draft
-webkit-box-lines : single;
-moz-box-lines : single;
box-lines : single;
// support the 2011 Draft
-ms-flex-wrap : nowrap;
// support current (as at 2013)
-webkit-flex-wrap : nowrap;
-moz-flex-wrap : nowrap;
-ms-flex-wrap : nowrap;
flex-wrap : nowrap;
}
.flexbox-wrap(@wrapping) when (@wrapping = multiple), (@wrapping = wrap)
{
// support the 2009 Draft
-webkit-box-lines : multiple;
-moz-box-lines : multiple;
box-lines : multiple;
// support the 2011 Draft
-ms-flex-wrap : wrap;
// support current (as at 2013)
-webkit-flex-wrap : wrap;
-moz-flex-wrap : wrap;
-ms-flex-wrap : wrap;
flex-wrap : wrap;
}
.flexbox-wrap(@wrapping) when (@wrapping = wrap-reverse)
{
// not supported in the 2009 Draft
// support the 2011 Draft
-ms-flex-wrap : wrap-reverse;
// support current (as at 2013)
-webkit-flex-wrap : wrap-reverse;
-moz-flex-wrap : wrap-reverse;
-ms-flex-wrap : wrap-reverse;
flex-wrap : wrap-reverse;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment