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.

<div style="height:320px">

  <div class="parent">
    <div class="wrapper">
      <!-- To change aspect ratio, change SVG's width/height -->
      <img class="resizer" src='data:image/svg+xml;utf8,<svg height="2px" width="1px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"></svg>'></img>
      <div class="child">Child maintains aspect ratio as parent's height changes</div>


<div style="float:left;">
  <h2>How does this work?</h2>
  <p>`img` can update its width based on its height while mainating the aspect ratio as defined by its intrinsic size. Using an SVG we create an image with intrinsic aspect ratio we want and rely on the browser to resize the width when height changes.</p>
              .parent {
  padding: 10px;
  height: 300px;
  background: green;
  animation-name: resize;
  animation-duration: 4s;
  animation-iteration-count: infinite;
  animation-direction: alternate;

.resizer {
  display: block;
  width: auto;
  height: auto;

.wrapper {
  display: inline-block;
  height: 100%;
  position: relative;
  /* Chrome bug work-around. 
   * See https://bugs.chromium.org/p/chromium/issues/detail?id=707151
  padding-right: 0.0001%;

.child {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: red;
@keyframes resize {
    from {height: 300px;}
    to {height: 150px;}
Loading ..................