cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-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.

            
              <div class="info">
  <h1>Retina Image Mixin & Media Query</h1>
  <p>Easily replace background images in css with their @2x version.</p>
  <div class="bot">
    <div class="non"></div>
    <div class="retina"></div>
  </div>
  <p class="links"><a href="https://twitter.com/michaelarestad" target="_blank">@michaelarestad</a> // <a href="https://twitter.com/see8ch" target="_blank"/>@see8ch</a>
</div>

<div class="demo non"></div>
<div class="demo retina"></div>
            
          
!
            
              @import "compass/css3";

//  Retina Image Mixin & Media Query
//  Authors: 
//  Michael Arestad @michaelarestad
//  Chris Holder @see8ch


@mixin retina-background ($url, $file-type, $width: auto, $repeat: repeat, $ratio: 1.5, $suffix: "@2x") {
	
  background: url($url + "." + $file-type);
  background-repeat: $repeat;
  
  /* Media queries from https://github.com/thoughtbot/bourbon/blob/master/app/assets/stylesheets/css3/_hidpi-media-query.scss */
	@media only screen and (-webkit-min-device-pixel-ratio: $ratio),
    only screen and (min--moz-device-pixel-ratio: $ratio),
    only screen and (-o-min-device-pixel-ratio: #{$ratio}/1),
    only screen and (min-resolution: #{round($ratio*96)}dpi),
    only screen and (min-resolution: #{$ratio}dppx) {
		
    background: url($url + $suffix + "." + $file-type);
		background-size: $width auto;
	}
}







//  Demo Stuff
$bkgd-color: #16a085;
$shadow: darken($bkgd-color, 12%);

.info {
  position: relative;
  z-index: 2;
  width: 800px;
  margin: 50px auto;
  background: $bkgd-color;
  padding: 15px 0;
  text-align: center;
  font-family: 'helvetica';
  color: #ecf0f1;
  box-shadow: 7px 6px 0 $shadow;
  
  h1 {
    text-shadow: 2px 3px 0 $shadow;
  }
  p {
    margin-bottom: 35px;
  }
  
  .links {
    color:$shadow; 
    margin-bottom:5px;
    font-size:smaller;
  }
  
  a {  
    color:$shadow;    
    transition: all 400ms ease-in-out; 
    
    &:hover {color:#ecf0f1;}
  }
}
.bot {
  position: relative;
  width: 800px;
  height: 295px;
  border-top: 7px solid darken($shadow, 15%);
  border-bottom: 7px solid darken($shadow, 15%);
  
  .non,
  .retina {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 70%;
  }
  .non {
    background: url(http://michaelarestad.com/images/misc/bot.jpg);
    z-index: 1;
    border-right: 1px rgba(255,255,255,.8) solid;
    overflow: hidden;
    resize: horizontal;
    max-width: 800px;
  }
  .retina {
    left: 0;
    right: 0;
    @include retina-background('http://michaelarestad.com/images/misc/bot',jpg, 800px);
  }
}
.demo {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 50%;
}
.demo.non {
  background: url(http://www.see8ch.com/codepen/tiny_grid.png);
  z-index: 1;
  border-right: 2px #2980b9 solid;
  overflow: hidden;
  resize: horizontal;
}
.demo.retina {
  left: 0;
  right: 0;
  @include retina-background('http://www.see8ch.com/codepen/tiny_grid',png, 26px);
}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console