Run Less in jsFiddle
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/less.js/1.6.3/less.min.js"></script>
<style media="screen">
div {
background: crimson;
width: 200px;
height: 100px;
position: relative;
float: left;
margin-right: 20px;
}
</style>
<div class="example-1"></div>
<div class="example-2"></div>
<div class="example-3"></div>
<div class="example-4"></div>
CSS
// out: style.css
.clipping(@colorOne; @colorTwo; @width; @direction; @position; @side) {
display: inline-block;
width: @width;
height: 20%;
position: absolute;
content: " ";
& when (@direction = 'up') {
background: linear-gradient(to top left, @colorOne 0%, @colorOne 50%, @colorTwo 50%, @colorTwo 100%);
}
& when (@direction = 'down') {
background: linear-gradient(to top right, @colorOne 0%, @colorOne 50%, @colorTwo 50%, @colorTwo 100%);
}
& when (@position = top) {
top: 0;
}
& when (@position = bottom) {
bottom: 0;
}
& when (@side = 'left') {
left: 0;
}
& when (@side = 'right') {
right: 0;
}
}
.clipping-single(@colorOne; @colorTwo; @direction; @position) {
&:before {
.clipping(@colorOne; @colorTwo; 100%; @direction; @position; 'left');
}
}
.clipping-double(@colorOne; @colorTwo; @direction; @position) {
& when (@direction = 'up') {
&:before {
.clipping(@colorOne; @colorTwo; 50%; 'up'; @position; 'left');
}
&:after {
.clipping(@colorOne; @colorTwo; 50%; 'down'; @position; 'right');
}
}
& when (@direction = 'down') {
&:before {
.clipping(@colorOne; @colorTwo; 50%; 'down'; @position; 'left');
}
&:after {
.clipping(@colorOne; @colorTwo; 50%; 'up'; @position; 'right');
}
}
}
.example-1 {
.clipping-double(crimson, #fff, 'up', top);
}
.example-2 {
.clipping-double(#fff, crimson, 'down', bottom);
}
.example-3 {
.clipping-single(#fff, crimson, 'down', bottom);
}
.example-4 {
.clipping-single(crimson, #fff, 'up', top);
}
JavaScript
/*
jsFiddle does not directly support Less so we need these bits of code to bring it here.
Twitter: @aaronlayton
Modified by meri
Updated by max
*/
// Step 1: Select the style element and change it to text/less
$('head style[type="text/css"]').attr('type','text/less');
// Step 2: Set development mode to see errors
less.env = 'development';
// Step 3: Tell Less to refresh the styles
less.refreshStyles();