Skip to content

Instantly share code, notes, and snippets.

@lucien144
Last active March 15, 2018 23:46
Show Gist options
  • Save lucien144/7dce67346d424f5998ccf9baeacdeb26 to your computer and use it in GitHub Desktop.
Save lucien144/7dce67346d424f5998ccf9baeacdeb26 to your computer and use it in GitHub Desktop.
LESS mixins
/**
* Layout mixins
*/
.top-left(@top: 0, @left: 0, @zindex: '', @position: absolute) when (@zindex = '') {
position: @position;
top: @top;
left: @left;
}
.top-left(@top: 0, @left: 0, @zindex: '', @position: absolute) when not (@zindex = '') {
position: @position;
top: @top;
left: @left;
z-index: @zindex;
}
.top-left-f(@top: 0, @left: 0, @zindex: '', @position: fixed) {
.top-left(@top, @left, @zindex, @position);
}
.top-right(@top: 0, @right: 0, @zindex: '', @position: absolute) when (@zindex = '') {
position: @position;
top: @top;
right: @right;
}
.top-right(@top: 0, @right: 0, @zindex: '', @position: absolute) when not (@zindex = '') {
position: @position;
top: @top;
right: @right;
z-index: @zindex;
}
.bottom-left(@bottom: 0, @left: 0, @zindex: '', @position: absolute) when (@zindex = '') {
position: @position;
bottom: @bottom;
left: @left;
}
.bottom-left(@bottom: 0, @left: 0, @zindex: '', @position: absolute) when not (@zindex = '') {
position: @position;
bottom: @bottom;
left: @left;
z-index: @zindex;
}
.bottom-right(@bottom: 0, @right: 0, @zindex: '', @position: absolute) when (@zindex = '') {
position: @position;
bottom: @bottom;
right: @right;
}
.bottom-right(@bottom: 0, @right: 0, @zindex: '', @position: absolute) when not (@zindex = '') {
position: @position;
bottom: @bottom;
right: @right;
z-index: @zindex;
}
.size(@width: auto, @height: -1) when (@height = -1) {
width: @width;
height: @width;
}
.size(@width: auto, @height: -1) when not (@height = -1) {
width: @width;
height: @height;
}
.center(@t: 0, @r: auto, @b: 0, @l: auto) {
margin: @t @r @b @l;
}
.pseudo(@display: inline-block) {
display: @display;
content: "";
}
/**
* Design mixins - colors, backgrounds, ...
* @type {[type]}
*/
.bg(@image, @position: 0 0, @repeat: no-repeat, @color: transparent) {
background: @color url(@image) @position @repeat;
}
.bgc(@color: #fff) {
background-color: @color;
}
// TOP triangle
.triangle-t(@width, @height, @color) {
border-style: solid;
border-width: 0 @width/2 @height @width/2;
border-color: transparent transparent @color transparent;
}
// BOTTOM triangle
.triangle-b(@width, @height, @color) {
border-style: solid;
border-width: @height @width/2 0 @width/2;
border-color: @color transparent transparent transparent;
}
/**
* Scott Kellum image replacement
*/
.skir(@b: inline-block) {
display: @b; text-indent: 100%; white-space: nowrap; overflow: hidden; border: none;
}
.sprite {
.skir();
}
.font-antialiasing() {
-webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
/**
* Other mixins
*/
.test(@c: #f00) {
border: 1px solid @c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment