Last active
May 9, 2023 13:12
-
-
Save mistergraphx/5e7983d2cb1226c98860 to your computer and use it in GitHub Desktop.
media-stack and media-queries :
From http://hmphry.com/useful-sass-mixins
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
// ---- | |
// libsass (v3.2.4) | |
// ---- | |
$media-stack: | |
(group: tablet, id: general, rule: "only screen and (min-device-width: 700px)"), | |
(group: small, id: general, rule: "only screen and(min-device-width: 1100px)"), | |
(group: small, id: inbetween, rule: "only screen and(min-device-width: 1100px) and (max-device-width: 1400px)"), | |
(group: large, id: general, rule: "only screen and(min-device-width: 1400px)"), | |
(group: print, id: general, rule: "only print"), | |
(group: custom, id: screen, rule: "only screen and"); | |
@mixin media($group, $id: general, $customRule: ""){ | |
@each $media in $media-stack{ | |
@if($group == map-get($media, group) and $id == map-get($media, id)){ | |
$rule: map-get($media, rule); | |
@media #{$rule} #{$customRule} {@content} | |
} | |
} | |
} | |
// USAGE | |
h1{ | |
color: #333; | |
@include media(tablet){ | |
font-size: 1rem; | |
}; | |
@include media(tablet, general, " and (min-device-pixel-ratio: 2)"){ | |
font-size: 1rem; | |
}; | |
@include media(small, inbetween){ | |
font-size: 1.2rem; | |
}; | |
@include media(small){ | |
color: #000; | |
}; | |
@include media(custom," (max-device-width: 360px)"){ | |
color: blue; | |
}; | |
} | |
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
h1 { | |
color: #333; | |
} | |
@media only screen and (min-device-width: 700px) { | |
h1 { | |
font-size: 1rem; | |
} | |
} | |
@media only screen and (min-device-width: 700px) and (min-device-pixel-ratio: 2) { | |
h1 { | |
font-size: 1rem; | |
} | |
} | |
@media only screen and (min-device-width: 1100px) and (max-device-width: 1400px) { | |
h1 { | |
font-size: 1.2rem; | |
} | |
} | |
@media only screen and (min-device-width: 1100px) { | |
h1 { | |
color: #000; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment