Skip to content

Instantly share code, notes, and snippets.

@Snugug
Created April 25, 2012 15:41
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Snugug/2490750 to your computer and use it in GitHub Desktop.
Save Snugug/2490750 to your computer and use it in GitHub Desktop.
Media Query Sass Mixin
//////////////////////////////
// Generalized Media Query Mixin
//
// Requires Sass 3.2+
// Until released:
// (sudo) gem install sass --pre
//////////////////////////////
@mixin media-query($value, $operator: 'min-width', $query: 'screen') {
@media #{$query} and (#{$operator}: #{$value}) {
@content;
}
}
//////////////////////////////
// Usage
//////////////////////////////
#foo {
background-color: red;
@include media-query(500px) {
background-color: green;
}
}
//////////////////////////////
// Output
//////////////////////////////
#foo {
background-color: red;
}
@media screen and (min-width: 500px) {
#foo {
background-color: green;
}
}
@Snugug
Copy link
Author

Snugug commented Apr 25, 2012

As per Scott Kellum's suggestion, made the 'min-width' operator a default.

@scottkellum
Copy link

awesome :)

@Snugug
Copy link
Author

Snugug commented Apr 25, 2012

This has officially come to a head with a Variable Driven respond-to Mixin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment