Created
May 29, 2013 20:38
-
-
Save simbo/5673640 to your computer and use it in GitHub Desktop.
useful LESS functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ============================================================================= | |
Box-Sizing | |
========================================================================== */ | |
.box-sizing( @mode ) { | |
-webkit-box-sizing: @mode; | |
-moz-box-sizing: @mode; | |
-ms-box-sizing: @mode; | |
-o-box-sizing: @mode; | |
box-sizing: @mode; | |
} | |
.border-box() { | |
.box-sizing( border-box ); | |
} | |
.content-box() { | |
.box-sizing( content-box ); | |
} | |
/* ============================================================================= | |
User-Select | |
========================================================================== */ | |
.user-select( @mode: none ) { | |
-webkit-user-select: @mode; | |
-moz-user-select: @mode; | |
-ms-user-select: @mode; | |
-o-user-select: @mode; | |
user-select: @mode; | |
} | |
/* ============================================================================= | |
Tab Size | |
========================================================================== */ | |
.tab-size( @size: 4 ) { | |
-moz-tab-size: @size; | |
-o-tab-size: @size; | |
tab-size: @size; | |
} | |
/* ============================================================================= | |
Opacity | |
========================================================================== */ | |
.opacity( @value: 1 ) { | |
-ms-filter: ~`"\"progid:DXImageTransform.Microsoft.Alpha(Opacity="+("@{value}"*100)+")\""`; | |
filter: ~`"alpha(opacity="+("@{value}"*100)+")"`; | |
opacity: @value; | |
} | |
/* ============================================================================= | |
Border-Radius | |
========================================================================== */ | |
.border-radius( @radius: 3*@px ) { | |
-webkit-border-radius: @radius; | |
-moz-border-radius: @radius; | |
-ms-border-radius: @radius; | |
-o-border-radius: @radius; | |
border-radius: @radius; | |
} | |
/* ============================================================================= | |
Transformations | |
========================================================================== */ | |
.rotate( @transform ) { | |
-webkit-transform: rotate(@transform); | |
-moz-transform: rotate(@transform); | |
-ms-transform: rotate(@transform); | |
-o-transform: rotate(@transform); | |
transform: rotate(@transform); | |
} | |
/* ============================================================================= | |
Box-Shadow | |
========================================================================== */ | |
.box-shadow( @shadow, @more... ) when not ( @more = ~'' ) { | |
@shadow: ~`"@{arguments}".substr(1,"@{arguments}".length-2)`; | |
-webkit-box-shadow: @shadow; | |
-moz-box-shadow: @shadow; | |
-ms-box-shadow: @shadow; | |
-o-box-shadow: @shadow; | |
box-shadow: @shadow; | |
} | |
.box-shadow( @shadow ) { | |
-webkit-box-shadow: @shadow; | |
-moz-box-shadow: @shadow; | |
-ms-box-shadow: @shadow; | |
-o-box-shadow: @shadow; | |
box-shadow: @shadow; | |
} | |
/* ============================================================================= | |
Gradients | |
========================================================================== */ | |
.gradient( @gradient_type, @gradient_direction, @gradient_def... ) { | |
@gradient: ~`"@{gradient_def}".substr(1,"@{gradient_def}".length-2)`; | |
@gradient_direction_prefixed: | |
~`(function(dir){ | |
switch(dir) { | |
case 'to right': return 'left'; | |
case 'to right bottom': return 'left top'; | |
case 'to right top': return 'left bottom'; | |
case 'farthest-side at center center': return 'center center, farthest-side'; | |
case 'to bottom': default: return 'top'; | |
}; | |
})("@{gradient_direction}".substr(1,"@{gradient_direction}".length-2).split(', ').join(' '))`; | |
background-image: ~`"-webkit-@{gradient_type}-gradient( @{gradient_direction_prefixed}, @{gradient} )"`; // Chrome10+,Safari5.1+ | |
background-image: ~`"-moz-@{gradient_type}-gradient( @{gradient_direction_prefixed}, @{gradient} )"`; // FF3.6+ | |
background-image: ~`"-ms-@{gradient_type}-gradient( @{gradient_direction_prefixed}, @{gradient} )"`; // IE10+ | |
background-image: ~`"-o-@{gradient_type}-gradient( @{gradient_direction_prefixed}, @{gradient} )"`; // Opera 11.10+ | |
background-image: ~`"@{gradient_type}-gradient( "+"@{gradient_direction}".substr(1,"@{gradient_direction}".length-2).split(', ').join(' ')+", @{gradient} )"`; // W3C | |
} | |
.gradient-vertical( @gradient... ) { | |
.gradient( linear, to bottom, @gradient ); | |
} | |
.gradient-vertical-repeating( @gradient... ) { | |
.gradient( repeating-linear, to bottom, @gradient ); | |
} | |
.gradient-horizontal( @gradient... ) { | |
.gradient( linear, to right, @gradient ); | |
} | |
.gradient-horizontal-repeating( @gradient... ) { | |
.gradient( repeating-linear, to right, @gradient ); | |
} | |
.gradient-diagonal-down( @gradient... ) { | |
.gradient( linear, to right bottom, @gradient ); | |
} | |
.gradient-diagonal-up( @gradient... ) { | |
.gradient( linear, to right top, @gradient ); | |
} | |
.gradient-radial( @gradient... ) { | |
.gradient( radial, farthest-side at center center, @gradient ); | |
} | |
/* ============================================================================= | |
Function for generating @font-face definition | |
========================================================================== */ | |
.font-face( @family, @file, @weight: 400, @style: normal ) { | |
(~"@font-face") { | |
font-family: @family; | |
font-weight: @weight; | |
font-style: @style; | |
src: url('../fonts/@{file}.eot'); | |
src: url('../fonts/@{file}.eot?#iefix') format('embedded-opentype'), | |
url('../fonts/@{file}.woff') format('woff'), | |
url('../fonts/@{file}.ttf') format('truetype'); | |
} | |
} | |
/* ============================================================================= | |
Clearfix | |
========================================================================== */ | |
.clearfix( @selector: '.clearfix' ) { | |
(~"@{selector}:after,@{selector}:before") { | |
content: " "; | |
display: table; | |
} | |
(~"@{selector}:after") { | |
clear: both; | |
} | |
(~"@{selector}") { | |
*zoom: 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment