Announcing LESS CSS Toolkit
I've recently starting developing using LESS CSS ( lesscss.org), and quickly decided that I would benefit from a toolkit containing mixins that I would use over and over, such as border-radius or box-shadow.
Enter LESS CSS Toolkit. You can import this file at the beginning of your LESS project, and then have access to the following mixins:
What you get:
- Animation
- Background Properties
- Border Image
- Border Radius
- Box Shadow
- Box Sizing
- CSS Columns
- Easy Clear
- FlexBox Properties
- Gradient
- Transform Properties
- CSS Transitions
Animation
.animation(@name, @duration, @iteration-count, @timing)
Usage:
1.myElement{ .animation(myAnimationName, .5s, 1, ease-in-out); }
Will result in
1.myElement {2-moz-animation-name: myAnimationName;3-moz-animation-duration: 0.5s;4-moz-animation-iteration-count: 1;5-moz-animation-timing-function: ease-in-out;6-webkit-animation-name: myAnimationName;7-webkit-animation-duration: 0.5s;8-webkit-animation-iteration-count: 1;9-webkit-animation-timing-function: ease-in-out;10-ms-animation-name: myAnimationName;11-ms-animation-duration: 0.5s;12-ms-animation-iteration-count: 1;13-ms-animation-timing-function: ease-in-out;14-o-animation-name: myAnimationName;15-o-animation-duration: 0.5s;16-o-animation-iteration-count: 1;17-o-animation-timing-function: ease-in-out;18animation-name: myAnimationName;19animation-duration: 0.5s;20animation-iteration-count: 1;21animation-timing-function: ease-in-out;22}
Background Properties
.background-clip(@clip)
, .background-origin(@origin)
and .background-size(@size)
Usage:
1.myElement{ .background-clip(padding-box); .background-origin(border-box) .background-size(250px 150px);
Will result in
1.myElement{2-moz-background-clip: padding-box;3-webkit-background-clip: padding-box;4background-clip: padding-box;56-moz-origin-size: border-box;7-o-origin-size: border-box;8-webkit-origin-size: border-box;9origin-size: border-box;1011-moz-background-size 250px 150px;12-o-background-size: 250px 150px;13-webkit-background-size: 250px 150px;14background-size: 250px 150px;15}
Border Image
.border-image(@img, @number, @repeat: stretch)
Usage:
1.myElement{ .border-image(url(img.gif), 25 25 25 25, round round); }
Will result in:
1.myElement {2-moz-border-image: url(img.gif), 25 25 25 25, round round;3-webkit-border-image: url(img.gif), 25 25 25 25, round round;4-ms-border-image: url(img.gif), 25 25 25 25, round round;5-o-border-image: url(img.gif), 25 25 25 25, round round;6border-image: url(img.gif), 25 25 25 25, round round;7}
Border Radius
.border-radius(@radius)
Usage:
1.myElement{ .border-radius(5px); }
Will result in:
1.myElement {2-moz-border-radius: 5px;3-webkit-border-radius: 5px;4-o-border-radius: 5px;5border-radius: 5px;6}
Box Shadow
.box-shadow(@shadow)
Usage:
1.myElement{ .box-shadow(3px 3px 2px rgba(0,0,0,.3)); }
Will result in:
1.myElement {2-webkit-box-shadow: 3px 3px 2px rgba(0, 0, 0, 0.3);3-moz-box-shadow: 3px 3px 2px rgba(0, 0, 0, 0.3);4box-shadow: 3px 3px 2px rgba(0, 0, 0, 0.3);5}
Box Sizing
.box-sizing(@sizing)
Usage:
1.myElement{ .box-sizing(border-box); }
Will result in:
1.myElement {2-moz-box-sizing: border-box;3-webkit-box-sizing: border-box;4box-sizing: border-box;5}
CSS Columns
.columns(@columnValue, @gap: normal, @rule: none)
Usage:
1.myElement{ .columns(3); }
Will result in:
1.myElement {2-moz-columns: 3;3-moz-column-gap: normal;4-moz-column-rule: none;56-webkit-columns: 3;7-webkit-column-gap: normal;8-webkit-column-rule: none;910columns: 3;11column-gap: normal;12column-rule: none;13}
Easy Clear
.easyclear()
Applies an updated easy clear fix to the :after psuedo-element (for times when overflow:auto
isn't an option)
Usage:
1.myElement{ .easyclear; }
Will result in:
1.myElement:after {2visibility: hidden;3display: block;4font-size: 0;5content: ' ';6clear: both;7height: 0;8}
FlexBox Properties
.flexbox(@orient: horizontal, @pack: start, @align: stretch, @direction: normal)
.box-flex(@flex: 1)
Usage:
1.myElement{ .flexbox; }2.myElement div{ .box-flex; }
Will result in:
1.myElement {2display: -webkit-box;3-webkit-box-orient: horizontal;4-webkit-box-pack: start;5-webkit-box-align: stretch;6-webkit-box-direction: normal;78display: -moz-box;9-moz-box-orient: horizontal;10-moz-box-pack: start;11-moz-box-align: stretch;12-moz-box-direction: normal;1314display: -ms-box;15-ms-box-orient: horizontal;16-ms-box-pack: start;17-ms-box-align: stretch;18-ms-box-direction: normal;1920display: -o-box;21-o-box-orient: horizontal;22-o-box-pack: start;23-o-box-align: stretch;24-o-box-direction: normal;2526display: box;27box-orient: horizontal;28box-pack: start;29box-align: stretch;30box-direction: normal;31}32.myElement div {33-moz-box-flex: 1;34-webkit-box-flex: 1;35-ms-flex: 1;36-o-flex: 1;37box-flex: 1;38}
Gradient
.gradient(@startcolor, @stopcolor, @startpoint: center top, @endpoint: center bottom)
This creates a simple, two-color gradient. It defaults to top-to-bottom.
Usage:
1.myElement{ .gradient(#000, #fff); }
Will result in:
1.myElement {2background: -webkit-gradient(3linear,4center top,5center bottom,6color-stop(0, #000),7color-stop(0.5, #fff)8);9background: -webkit-linear-gradient(center top, #000, #fff);10background: -o-linear-gradient(center top, #000, #fff);11background: -moz-linear-gradient(center top, #000, #fff);12background: linear-gradient(center top, #000, #fff);13}
Transform Properties
.transform(@transform)
.transform-origin(@origin)
Usage:
1.myElement{ .transform(rotate(45deg)); .transform-origin(center center) }
Will result in:
1.myElement {2-moz-transform: rotate(45deg);3-webkit-transform: rotate(45deg);4-ms-transform: rotate(45deg);5transform: rotate(45deg);67-moz-transform-origin: center center;8-webkit-transform-origin: center center;9-ms-transform-origin: center center;10transform-origin: center center;11}
CSS Transitions
.transition(@transition)
Usage:
1.myElement{ .transition(all ease-out .5s); }
Will result in:
1.myElement {2-webkit-transition: all ease-out 0.5s;3-moz-transition: all ease-out 0.5s;4-o-transition: all ease-out 0.5s;5-ms-transition: all ease-out 0.5s;6transition: all ease-out 0.5s;7}
That's all for now
This is a work in progress, so keep track of the project on github as I'll probably be adding to it down the line. Any suggestions are always welcome.