mixins for media queries code example

Example 1: 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 2: 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