css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <h1>Flexy (Variable Aspect Ratio) Image Grid</h1>
<h2>A demo. Also I want an orphans declaration but for flexbox.</h2>

<div class="container">

  <img src="http://placekitten.com/550/605?image=1" />
  <p style="background-image: url('http://placekitten.com/550/605?image=1');"></p>
  <figcaption>Crouch, shake butt, <a href="#">prepare to pounce</a>.</figcaption>

  <img src="http://placekitten.com/551/401?image=2" />
  <p style="background-image: url('http://placekitten.com/551/401?image=2');"></p>
  <figcaption>I am the best pounce upon little yarn mouse</figcaption>

  <img src="http://placekitten.com/650/400?image=3" />
  <p style="background-image: url('http://placekitten.com/650/400?image=3');"></p>
  <figcaption>Hide head under blanket so no one can see.</figcaption>

  <img src="http://placekitten.com/575/400?image=4" />
  <p style="background-image: url('http://placekitten.com/575/400?image=4');"></p>
  <figcaption>Put toy mouse in food bowl.</figcaption>

  <img src="http://placekitten.com/600/450?image=5" />
  <p style="background-image: url('http://placekitten.com/600/450?image=5');"></p>
  <figcaption>Intently stare at the same spot.</figcaption>

  <img src="http://placekitten.com/1000/500?image=6" />
  <p style="background-image: url('http://placekitten.com/1000/500?image=6'); background-position: 70% top;"></p>
  <figcaption>Attack feet scamper and hunt.</figcaption>

  <img src="http://placekitten.com/351/601?image=15" />
  <p style="background-image: url('http://placekitten.com/351/601?image=15'); background-position: center center;"></p>
  <figcaption>Love to play with owner's hair tie.</figcaption>


<p>The images have different aspect ratios, but are utilizing <code>background-size: cover;</code> to appear similar. The image grid is handled with flexbox, and a <code>min-width</code> specification on the images (which can of course be changed with media queries).</p>
<p>But at certain viewport widths, the last image orphans and stretches way too. It would be nice if there were a <code>flex-orphans</code> declaration (similar to <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/orphans">https://developer.mozilla.org/en-US/docs/Web/CSS/orphans</a> but for flexbox) to control how many children might appear in a single flex row.</p>

              div.container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  margin: .5rem;

figure {
  flex-grow: 1;
  min-width: 225px;
  height: 300px;
  margin: .5rem;
  position: relative;

  img { 
    display: none;
  p {
    height: 100%;
    width: 100%;
    margin: 0;
    background-size: cover;
    background-repeat: none;
    background-position: 50% 50%;
    &:hover {
      cursor: pointer;
      filter: none;
  figcaption {
    position: absolute;
    bottom: 0;
    width: 100%;
    box-sizing: border-box;
    padding: .5rem;
    color: white;
    background-color: rgba(0,0,0,.6);

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................