Skip to content

Instantly share code, notes, and snippets.

@subhaze
Created May 29, 2015 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subhaze/a98a08ec840ca525d263 to your computer and use it in GitHub Desktop.
Save subhaze/a98a08ec840ca525d263 to your computer and use it in GitHub Desktop.
mixins to hit specific screen sizes using bootstrap's screen variables
/* Extra small devices (phones, less than 768px) */
/* No media query since this is the default in Bootstrap */
/* Small devices (tablets, 768px and up) */
@media (min-width: $screen-sm-min) { ... }
/* Medium devices (desktops, 992px and up) */
@media (min-width: $screen-md-min) { ... }
/* Large devices (large desktops, 1200px and up) */
@media (min-width: $screen-lg-min) { ... }
// Going screen specific now, with mixins
@mixin xs-screen {
@media (max-width: #{$screen-xs-max}) {
@content;
}
}
@mixin sm-screen {
@media (min-width: $screen-sm-min) and (max-width: $screen-sm-max) {
@content;
}
}
@mixin md-screen {
@media (min-width: $screen-md-min) and (max-width: $screen-md-max) {
@content;
}
}
@mixin lg-screen {
@media (min-width: $screen-lg-min) {
@content;
}
}
// Usage
div{
@include xs-screen {
// basically only show on phones
}
@include sm-screen {
// smaller tablets/portrait view
}
@include md-screen {
// larger tablets/landscape/some desktops
}
@include lg-screen {
// desktop+
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment