Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Trying to polyfill lack of browser support for attr()'s 'url' type-or-unit</h1>

<p>According to (my understanding of) the spec, this CSS should change the content values from <code>attr(data-whatever, url)</code> to <code>url(data-whatever's-value)</code> but it doesn't. This is my attempt to polyfill a simple responsive image solution until browser support catches up with the spec.</p>

<img src="https://s3.amazonaws.com/lesjames-media/breakpoint/mobile.gif" data-medium="https://s3.amazonaws.com/lesjames-media/breakpoint/tablet.gif" data-large="https://s3.amazonaws.com/lesjames-media/breakpoint/desktop.gif">
              
            
!

CSS

              
                @import "compass/css3";

body {
  margin: 0;
  padding: 5%;
}

code {
  font-size: 0.8em;
  display: inline-block;
  background: #f4f4f4;
  border: 1px solid #ddd;
  padding: 0 2px;
}

@media (min-width: 31em) {
  img[data-medium] {
    content: attr(data-medium, url);
  }
}
@media (min-width: 60em) {
  img[data-large] {
    content: attr(data-large, url);
  }
}
@media (min-width: 75em) {
  img[data-x-large] {
    content: attr(data-x-large, url);
  }
}

              
            
!

JS

              
                (function(d, exp, undefined) {
  'use strict';
  
  function ResponsiveImages(selector) {
    var base = this,
        resize = exp.onresize;
    
    // bind resize method to 
    // window.onresize
    exp.onresize = function() {
      if (typeof resize === 'function') { 
        resize(); 
      }
      
      base.resize();
    };
    
    this.images = d.querySelectorAll('img');
    this.length = this.images.length;
    this.resize();
  }
  
  ResponsiveImages.prototype.resize = function() {
    if (!this.length || !exp.getComputedStyle) {
      return;
    }
    
    for (var i = 0; i < this.length; i++) {
      var img = this.images[i],
          styles = exp.getComputedStyle(img);
      
      // always empty.... WHY?! :(
      console.log(styles.content);
    }
  };
  
  exp.ResponsiveImages = ResponsiveImages;
}(document, this));


new ResponsiveImages();
              
            
!
999px

Console