Skip to content

Instantly share code, notes, and snippets.

@marcialca
Created November 19, 2014 22:42
Show Gist options
  • Save marcialca/9dbc54bf8dd2c91504df to your computer and use it in GitHub Desktop.
Save marcialca/9dbc54bf8dd2c91504df to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.7)
// Compass (v1.0.1)
// ----
// List map-like value getter
// -------------------
// To simulate associative arrays
// Source: http://hugogiraudel.com/2013/08/12/sass-functions/#mapping
@function map-getter($listmap, $value) {
@each $item in $listmap {
$index: index($item, $value);
@if $index {
$return: if($index == 1, 2, $index);
@return nth($item, $return);
}
}
@return false;
}
$site-breakpoints: (
"small": "22.5em", //360px
"medium": "45em", //720px
"large": "67.5em", //1080px
);
// Query (new version of respond-to)
@mixin query($breakpoint) {
$val: map-getter($site-breakpoints, $breakpoint);
@if $val == false {
@if type-of($breakpoint) == number {
@media only screen and ("min-width": $breakpoint) {
@content;
}
}
@else {
@error "QUERY MIXINS ERROR: INVALID ARGUMENT"
}
}
@else {
@media only screen and ("min-width": $val) {
@content;
}
}
};
.body {
@include query("small") {
color: red;
}
@include query("medium") {
color: red;
}
@include query("large") {
color: red;
}
@include query(768px) {
color: red;
}
@include query(50em) {
color: red;
}
}
@media only screen and (min-width: 22.5em) {
.body {
color: red;
}
}
@media only screen and (min-width: 45em) {
.body {
color: red;
}
}
@media only screen and (min-width: 67.5em) {
.body {
color: red;
}
}
@media only screen and (min-width: 768px) {
.body {
color: red;
}
}
@media only screen and (min-width: 50em) {
.body {
color: red;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment