Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                .container
  .row
    .col-sm-12.text-center
      h1 Auto-scaling iframes
      p
        != 'The nature of iframes is to be static and unflexible.'
        br
        strong Let's make them responsive!
.container
  .row
    .col-sm-4
      h2 33% iframe
      iframe(width="800" height="600" frameborder="0" src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3168.6392906210613!2d-122.08624618424679!3d37.42199987982524!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x808fba02425dad8f%3A0x6c296c66619367e0!2sGoogleplex!5e0!3m2!1sde!2sch!4v1479590858003")
    .col-sm-8
      h2 66% iframe
      iframe(width="800" height="600" frameborder="0" src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3168.6392906210613!2d-122.08624618424679!3d37.42199987982524!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x808fba02425dad8f%3A0x6c296c66619367e0!2sGoogleplex!5e0!3m2!1sde!2sch!4v1479590858003")
  .row
    .col-sm-6
      h2 50% iframe
      iframe(width="800" height="600" frameborder="0" src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3168.6392906210613!2d-122.08624618424679!3d37.42199987982524!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x808fba02425dad8f%3A0x6c296c66619367e0!2sGoogleplex!5e0!3m2!1sde!2sch!4v1479590858003")
    .col-sm-6
      h2 50% iframe (16:9)
      iframe(width="800" height="450" frameborder="0" src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3168.6392906210613!2d-122.08624618424679!3d37.42199987982524!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x808fba02425dad8f%3A0x6c296c66619367e0!2sGoogleplex!5e0!3m2!1sde!2sch!4v1479590858003")
.container-fluid
  .row
    .col-sm-12
      h2 100% iframe (4:1; full-with)
      iframe(width="800" height="200" frameborder="0" src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3168.6392906210613!2d-122.08624618424679!3d37.42199987982524!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x808fba02425dad8f%3A0x6c296c66619367e0!2sGoogleplex!5e0!3m2!1sde!2sch!4v1479590858003")
      
              
            
!

CSS

              
                
              
            
!

JS

              
                // Auto-scaling iframes
//-----------------------


// VanillaJS version

function iframeAutoScale() {
  
  'use strict';
  
  var
    iframes = document.getElementsByTagName('iframe'),
    index = 0;

  if (iframes.length > 0) {
    for (index = 0; index < iframes.length; index++) {
      var
        iframe = iframes[index],
        parent = iframe.parentElement,
        parentPadding = parseInt(window.getComputedStyle(parent, null).getPropertyValue('padding-left')) + parseInt(window.getComputedStyle(parent, null).getPropertyValue('padding-right')),
        parentWidth = parent.clientWidth - parentPadding,
        ratio = 0.75,	// default ratio (4:3)
        width = iframe.clientWidth,
        height = iframe.clientHeight;

      // overwrite default ratio if width and height attributes are not set
      if (width !== undefined && height !== undefined) {
        ratio = height / width;
      }
      
      iframe.setAttribute('width', parentWidth);
      iframe.setAttribute('height', parentWidth * ratio);
    }
  }
}

// onload
document.addEventListener('DOMContentLoaded', function () { 
  iframeAutoScale();
}, false);

// on window resize
window.onresize = function(event) {
  iframeAutoScale();
};



// jQuery Version

/*
function iframeAutoScale() {
  
  'use strict';
  
  $('iframe').each(function () {
    var
      parentWidth = $(this).parent().innerWidth(),
      ratio = 0.75,	// default ratio (4:3)
      width = $(this).attr('width'),
      height = $(this).attr('height');

    // overwrite default ratio if width and height attributes are not set
    if (width !== undefined && height !== undefined) {
      ratio = height / width;
    }

    $(this).attr('width', parentWidth);
    $(this).attr('height', parentWidth * ratio);
  });
}

// onload
$(document).ready(function () {
  iframeAutoScale();
});

// on window resize
$(window).resize(function () {
  iframeAutoScale();
});
*/

              
            
!
999px

Console