cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <section class="container">
  <h1>Media queries mixins</h1>
  
  <p>Two mixins for generating media queries. One for max widths and one for min widths</p>
  <h2>Usage: </h2>
  <pre>
    $phone = 480;
    body{
      // Min value
      @include min(900){
        background: #7096AD;
      }

      // Both
      @include max(899, 481){
        background: #C1D1DE;
      }

      //Variable use
      @include max($phone){
        background: #FFF9EF;
      }
    }
  </pre>
  <p>Compiles to: </p>
  
  <pre>
    @media only screen and (min-width: 56.25em) {
      body {
        background: #7096AD;
      }
    }
    @media only screen and (max-width: 56.1875em) and (min-width: 30.0625em) {
      body {
        background: #C1D1DE;
      }
    }
    @media only screen and (max-width: 30em) {
      body {
        background: #FFF9EF;
      }
    }
  </pre>
</section>
            
          
!
            
              @import "compass/css3";

$basefont: 16;

@function em($target, $context: $basefont){
  @return ($target/$context)+0em;
}

@mixin max($bp, $min: 'null', $device: 'screen'){
  $bp : em($bp);
  @if $min == 'null' {
    @media only #{$device} and (max-width: #{$bp}){@content;}
  } @else {
    $min : em($min);
    @media only #{$device} and (max-width: #{$bp}) and (min-width: #{$min}) {@content;}
  }
}

@mixin min($bp, $max: 'null', $device: 'screen'){
  $bp : em($bp);
  @if $max == 'null' {
    @media only #{$device} and (min-width: #{$bp}){@content;}
  } @else {
    $max : em($max);
    @media only #{$device} and (min-width: #{$bp}) and (max-width: #{$max}) {@content;}
  }
}

$phone: 480;

body{
  color: #111;
  .container{
    width: 70%;
    margin: 0 auto;
  }
  // Min value
  @include min(900){
    background: #7096AD;
  }
  
  // Both
  @include max(899, 481){
    background: #C1D1DE;
  }
  
  //Variable use
  @include max($phone){
    background: #FFF9EF;
  }
}
            
          
!
999px
Loading ..................

Console