Skip to content

Instantly share code, notes, and snippets.

@Andreyco
Last active March 10, 2016 09:56
Show Gist options
  • Save Andreyco/9710819 to your computer and use it in GitHub Desktop.
Save Andreyco/9710819 to your computer and use it in GitHub Desktop.
Positioning mixins similar to those ones in Stylus.
/**
* 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