Last active
March 10, 2016 09:56
-
-
Save Andreyco/9710819 to your computer and use it in GitHub Desktop.
Positioning mixins similar to those ones in Stylus.
This file contains hidden or 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
/** | |
* Set positioning properties (top|right|bottom|left). | |
* @param prop-value. String in format "top 10px". | |
*/ | |
.positioning-property(@prop-value) { | |
@property: extract(@prop-value, 1); | |
@value: extract(@prop-value, 2); | |
@{property}: @value; | |
} | |
/** | |
* Static position. | |
*/ | |
.static() { | |
position: static; | |
} | |
/** | |
* Absolute position. | |
*/ | |
.absolute() { | |
position: absolute; | |
} | |
.absolute(@a) { | |
.absolute; | |
.positioning-property(@a); | |
} | |
.absolute(@a, @b) { | |
.absolute; | |
.positioning-property(@a); | |
.positioning-property(@b); | |
} | |
/** | |
* Fixed position. | |
*/ | |
.fixed() { | |
position: fixed; | |
} | |
.fixed(@a) { | |
.fixed; | |
.positioning-property(@a); | |
} | |
.fixed(@a, @b) { | |
.fixed; | |
.positioning-property(@a); | |
.positioning-property(@b); | |
} | |
/** | |
* Relative position. | |
*/ | |
.relative() { | |
position: relative; | |
} | |
.relative(@a) { | |
.relative; | |
.positioning-property(@a); | |
} | |
.relative(@a, @b) { | |
.relative; | |
.positioning-property(@a); | |
.positioning-property(@b); | |
} | |
// Usage | |
h1 { | |
// !!! The order of passed values is completely up to you! | |
// You do not have to remember which comes first. | |
.fixed; | |
// or | |
.fixed(top 10px); | |
// or | |
.fixed(top 10px); | |
// or | |
.fixed(top 10px, left 100px); | |
// or | |
.fixed(right 10px, bottom 100px); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment