Skip to content

Instantly share code, notes, and snippets.

@mattmckenny
Created March 18, 2015 13:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmckenny/6f3701852be4ff737944 to your computer and use it in GitHub Desktop.
Save mattmckenny/6f3701852be4ff737944 to your computer and use it in GitHub Desktop.
Bootstrap/Less mixin to add responsive media query within original selector's declaration
//
// Load core variables
// --------------------------------------------------
@import "variables.less";
.breakpoint(@class, @rules) when (@class = xs) {
@media (min-width: @screen-xs-min) and (max-width: @screen-xs-max) {@rules();}
}
.breakpoint(@class, @rules) when (@class = sm) {
@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) {@rules();}
}
.breakpoint(@class, @rules) when (@class = md) {
@media (min-width: @screen-md-min) and (max-width: @screen-md-max) {@rules();}
}
.breakpoint(@class, @rules) when (@class = lg) {
@media (min-width: @screen-lg-min) {@rules();}
}
// Example Usage
.my-class {
height: 150px;
.breakpoint( md, {
height: 125px;
});
.breakpoint( sm, {
height: 100px;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment