scss media query mixin code example

Example 1: scss media query

$information-phone: "only screen and (max-width : 320px)";

@media #{$information-phone} {
  background: red;
}

Example 2: sass mixin

@mixin transform($property) {
  -webkit-transform: $property;
  -ms-transform: $property;
  transform: $property;
}
.box { @include transform(rotate(30deg)); }

Example 3: media screen scss mixin

// respond is the name of your mixin

    @mixin respond ($breakpoint) {

        // $breakpoint is simply a variable that can have several values

        @if $breakpoint==tablet {

            // here `laptop` is the value of $breakpoint
            // when call laptop, we mean the following piece of code        

        @media only screen and (max-width: 600px) {
          @content;
        }
      }

      @if $breakpoint==mobile {
        @media only screen and (max-width: 480px) {
          @content;
        }
      }
    }

Example 4: media query mixin

@mixin for-phone-only {  @media (max-width: 599px) { @content; }}
@mixin for-tablet-portrait-up {  @media (min-width: 600px) { @content; }}
@mixin for-tablet-landscape-up {  @media (min-width: 900px) { @content; }}
@mixin for-desktop-up {  @media (min-width: 1200px) { @content; }}
@mixin for-big-desktop-up {  @media (min-width: 1800px) { @content; }}

Tags:

Css Example