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 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.

Quick-add: + add another resource

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.

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.

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

<div class="container">

<figure>
  <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>
</figure>

<figure>
  <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>
</figure>

<figure>
  <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>
</figure>

<figure>
  <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>
</figure>

<figure>
  <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>
</figure>

<figure>
  <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>
</figure>

<figure>
  <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>
</figure>

</div>

<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);
  }

}
            
          
!
999px
Loading ..................

Console