Created
August 19, 2013 20:50
-
-
Save ftsanjuan/6274030 to your computer and use it in GitHub Desktop.
A SASS mixin to help generate responsive media query styles. Responsive breakpoints are based on Twitter Bootstrap 2 breakpoints.
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
/** | |
* Creates responsive media query styles for a particular media size | |
* Media type codes are: phone, subtablet, tablet, desktop, large-desktop | |
* | |
* Example usage: | |
* | |
* .header { | |
* @include responsify(phone) { | |
* width: 200px; | |
* } | |
* } | |
* | |
* The above style would apply "width: 200px" to the element with class of 'header' | |
* if the user's screen resolution is 480px wide or less. | |
* | |
* Credits to http://thesassway.com/intermediate/responsive-web-design-part-2 | |
* for inspiring this method of creating a responsive mixin for SASS and | |
* and Twitter Bootstrap for providing the RWD breakpoints. | |
* | |
*/ | |
@mixin responsify($media) { | |
// Landscape phones and down | |
// media-type code: phone | |
@if $media == phone { | |
@media (max-width: 480px) { | |
@content; | |
} | |
} | |
// Landscape phone to portrait tablet | |
// media-type code: subtablet | |
@else if $media == subtablet { | |
@media (min-width: 481px) and (max-width: 767px) { | |
@content; | |
} | |
} | |
// Portrait tablet to landscape and desktop | |
// repsonsive code: tablet | |
@else if $media == tablet { | |
@media (min-width: 768px) and (max-width: 979px) { | |
@content; | |
} | |
} | |
// Default: Desktop | |
// media-type code: desktop | |
@else if $media == desktop { | |
@media (min-width: 980px) and (max-width: 1209px) { | |
@content; | |
} | |
} | |
// Large desktop | |
// media-type code: large-desktop | |
@else if $media == large-desktop { | |
@media (min-width: 1210px) { | |
@content; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment