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

              
                <article class="teaser">
  <div class="teaser-image">
    <figure>
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/19101/anastasia-dulgier-675853-unsplash-1600.jpg" alt="Statue of a man with an umbrella in Prague, Photo by Anastasia Dulgier on Unsplash">
    </figure>
  </div>
  <div class="teaser-copy">
    <h2>@supports with CSS Grid and object-fit:cover</h2>
    <p>Our static tools and linear workflows aren’t the right fit for the flexible, diverse reality of today’s Web. Making prototyping a central element of your workflows will radically change how you approach problem solving and save you a lot of headaches. But most importantly, you will be creating the right products and features in a way that resonates with the true nature of the Web.</p>
  </div>
</article>
              
            
!

CSS

              
                *, *::before, *::after {
  box-sizing:border-box;
}

body {
  font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

figure {
  margin:0;
  padding:0;
}

.teaser {
  display:flex;
  flex-wrap: wrap;
  max-width:1600px;
  margin:0 auto;
  
  --modifier: calc(40rem - 100%);
  
  & > * {
    flex-basis:calc(50% - 2rem);
    flex-grow:1;
    flex-basis: calc(var(--modifier) * 999);
    margin:1rem;
    min-width:288px;
  }
}

.teaser-image {
  display:flex;
  position:relative;
  overflow:hidden;
  min-height:320px;
  
  /* we set a fixed aspect ratio for older browsers */
  &::before {
    display: block;
    content:'';
    width:100%;
    height:auto;
    padding-top:56.25%;
  }
}

.teaser-copy {
  display:flex;
  flex-direction:column;
  justify-content:center;
}

figure {
  width:100%;
  height:auto;
  
  /* the figure is positioned absolutely for the aspect ratio to work -> height now comes from .teaser-image::before */
  position:absolute;
  top:0;
  left:0;
  right:0;
  bottom:0;
}

img {
  max-width:100%;
 
  /* more stuff for older browsers: the min-width – together with the min-height of .teaser-image – maintains the aspect ratio and a min-size */
  position:relative;
  min-width:569px;
  height:100%;
  /* always center the image on both axes */
  left:50%;
  top:50%;
  transform:translateX(-50%) translateY(-50%)
}

@supports(object-fit:cover) {
  
  /* remove/reset what's not needed anymore */
  .teaser-image::before {
    display: none;
  }
  
  figure {
    position:static;
  }
  
  img {
    /* remove/reset what's not needed anymore */
    position:static;
    transform:none;
    min-width:0;
    
    width:100%;
    height:100%;
    object-fit:cover;
  }
}

@supports(display:grid){
   .teaser {
     display:grid;
     grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  }
}
              
            
!

JS

              
                
              
            
!
999px

Console