Skip to content

Instantly share code, notes, and snippets.

@AdmireNL
Last active August 29, 2015 14:09
Show Gist options
  • Save AdmireNL/cc8936bb2f2feff3ad10 to your computer and use it in GitHub Desktop.
Save AdmireNL/cc8936bb2f2feff3ad10 to your computer and use it in GitHub Desktop.
Media queries mixin with devices map
// ----
// Sass (v3.4.7)
// Compass (v1.0.1)
// ----
$devices: (tablet: 768px, phone: 320px);
@mixin respond-to($device) {
@if (map-has-key($devices, $device)) {
@media (max-width: map-get($devices, $device)) {
@content;
}
}
@else {
@warn "Device key not found.";
}
}
h1 {
width: 600px;
@include respond-to(tablet) {
width: 100%;
background: red;
}
@include respond-to(phone) {
width: 200px;
}
}
h1 {
width: 600px;
}
@media (max-width: 768px) {
h1 {
width: 100%;
background: red;
}
}
@media (max-width: 320px) {
h1 {
width: 200px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment