Skip to content

Instantly share code, notes, and snippets.

@nkabardin
Created December 1, 2016 12:44
Show Gist options
  • Save nkabardin/1b0e22e44736404a06365fe91c148932 to your computer and use it in GitHub Desktop.
Save nkabardin/1b0e22e44736404a06365fe91c148932 to your computer and use it in GitHub Desktop.
Universal and easily extendable SCSS media query mixins
@mixin media ($settings) {
$mediaSettings: ("only screen");
@each $rule, $value in $settings {
@if $rule == "min" {
$mediaSettings:
append(
$mediaSettings,
"and (min-device-width: #{$value})"
);
}
@if $rule == "max" {
$mediaSettings:
append(
$mediaSettings,
"and (max-device-width: #{$value})"
);
}
@if $rule == "orientation" {
$mediaSettings:
append(
$mediaSettings,
"and (orientation: #{$value})"
);
}
}
@media #{$mediaSettings} {
@content;
}
}
$tablet_breakpoint: 767px;
@mixin phone {
@include media ((max: $tablet_breakpoint)) {
@content;
}
}
@mixin tablet {
@include media ((min: $tablet_breakpoint + 1px)) {
@content;
}
}
@mixin landscape {
@include media ((orientation: landscape)) {
@content;
}
}
@mixin portrait {
@include media ((orientation: portrait)) {
@content;
}
}
@mixin tablet-landscape {
@include tablet {
@include landscape {
@content;
}
}
}
@mixin tablet-portrait {
@include tablet {
@include portrait {
@content;
}
}
}
@mixin phone-landscape {
@include phone {
@include landscape {
@content;
}
}
}
@mixin phone-portrait {
@include phone {
@include portrait {
@content;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment