mixins for breakpoints code example

Example 1: scss media query

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

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

Example 2: sass mixin breakpoint

@mixin breakpoint($class) {  
  @if $class == xs {    
	@media (max-width: 767px) { @content; }  }   
  @else if $class == sm {    
    @media (min-width: 768px) { @content; }  }   
  @else if $class == md {    
    @media (min-width: 992px) { @content; }  }   
  @else if $class == lg {    
    @media (min-width: 1200px) { @content; }  }   
  @else {    
    @warn "Breakpoint mixin supports: xs, sm, md, lg";  
  }
}

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;
        }
      }
    }

Tags:

Misc Example