Skip to content

Instantly share code, notes, and snippets.

@AlexandrBukhtatyy
Created March 27, 2018 08:22
Show Gist options
  • Save AlexandrBukhtatyy/b92ea4b9ebe8433c5e81b187ea288b6b to your computer and use it in GitHub Desktop.
Save AlexandrBukhtatyy/b92ea4b9ebe8433c5e81b187ea288b6b to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.21)
// Compass (v1.0.3)
// ----
@mixin response-rule($property, $defaultValue, $responsiveValues) {
& {
#{$property}: $defaultValue;
}
@each $media, $value in $responsiveValues {
@media #{$media} {
& {
#{$property}: $value;
}
}
}
}
// ======== USAGE DEMO ==============
$desktop: "(min-width: 1200px)";
$mobile: "(min-width: 450px)";
$tablet: "(min-width: 750px)";
body {
.p1 {
@include response-rule("font-size", 16px, ($desktop: 20px, $tablet: 18px));
}
.p2 {
@include response-rule("background-color", #fff, (
$desktop: #ddd,
$mobile: #eee,
$tablet: #ccc
))
}
}
body .p1 {
font-size: 16px;
}
@media (min-width: 1200px) {
body .p1 {
font-size: 20px;
}
}
@media (min-width: 750px) {
body .p1 {
font-size: 18px;
}
}
body .p2 {
background-color: #fff;
}
@media (min-width: 1200px) {
body .p2 {
background-color: #ddd;
}
}
@media (min-width: 450px) {
body .p2 {
background-color: #eee;
}
}
@media (min-width: 750px) {
body .p2 {
background-color: #ccc;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment