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.

            
              <main>

    <h1>A Demo of the Object Fit Property</h1>
    <p>The <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit">object-fit property</a> alters the way images get resized as their containing box is resized. Note: these are images in the HTML, not background images called by CSS.</p>
            
      <footer class="warning">This demo only works in browsers that support object-fit. If you can see this message, then your browser doesn't support the object-fit property. <p class="ciu_embed" data-feature="object-fit" data-periods="future_1,current,past_1,past_2">   <a href="http://caniuse.com/#feat=object-fit">Can I Use object-fit?</a> Data on support for the object-fit feature across the major browsers from caniuse.com. </p></footer>

      <ol>  
        <h2>An image that’s larger than its box</h2>    
        <li>
          <h4>original image (1920x1080px)</h4>
          <img class="original-image" src="http://labs.jensimmons.com/2016/examples/images/testscreen-large.jpg">
        </li>
        
        <li>
          <h4>object-fit: fill</h4>
          <img class="object-fit-fill" src="http://labs.jensimmons.com/2016/examples/images/testscreen-large.jpg">
        </li>
        
        <li>
          <h4>object-fit: contain</h4>
          <img class="object-fit-contain" src="http://labs.jensimmons.com/2016/examples/images/testscreen-large.jpg">
        </li>
        
        <li>
          <h4>object-fit: cover</h4>
          <img class="object-fit-cover" src="http://labs.jensimmons.com/2016/examples/images/testscreen-large.jpg">
        </li>
        
        <li>
          <h4>object-fit: none</h4>
          <img class="object-fit-none" src="http://labs.jensimmons.com/2016/examples/images/testscreen-large.jpg">
        </li>
        
        <li>
          <h4>object-fit: scale-down</h4>
          <img class="object-fit-scale" src="http://labs.jensimmons.com/2016/examples/images/testscreen-large.jpg">
        </li>
      </ol>
    
      <ol class="smaller-test-image">  
        <h2>An image that’s smaller than its box</h2>    
        <li>
          <h4>original image (267x150px)</h4>
          <img class="original-image" src="http://labs.jensimmons.com/2016/examples/images/testscreen-small.jpg">
        </li>
        
        <li>
          <h4>object-fit: fill</h4>
          <img class="object-fit-fill" src="http://labs.jensimmons.com/2016/examples/images/testscreen-small.jpg">
        </li>
        
        <li>
          <h4>object-fit: contain</h4>
          <img class="object-fit-contain" src="http://labs.jensimmons.com/2016/examples/images/testscreen-small.jpg">
        </li>
        
        <li>
          <h4>object-fit: cover</h4>
          <img class="object-fit-cover" src="http://labs.jensimmons.com/2016/examples/images/testscreen-small.jpg">
        </li>
        
        <li>
          <h4>object-fit: none</h4>
          <img class="object-fit-none" src="http://labs.jensimmons.com/2016/examples/images/testscreen-small.jpg">
        </li>
        
        <li>
          <h4>object-fit: scale-down</h4>
          <img class="object-fit-none" src="http://labs.jensimmons.com/2016/examples/images/testscreen-small.jpg">
        </li>
      </ol>
      
    </main>
            
          
!
            
              html {
  font-size: 18px;
  padding: 5%;
  font-family: Georgia, serif;
}
h4 { 
  font-weight: normal; 
  font-size: 0.8em; 
  margin-bottom: 10px; 
  margin-top: 0;
}
img { 
  height: 200px; 
  width: 100%;
  background-color: #ccc;
  border: 10px solid red;
}
.smaller-test-image img {
  border: 10px solid blue;  
}
img.original-image,
.smaller-test-image img.original-image  {
  margin-bottom: 50px;
  border-color: white;
}
ol {
  width: 45%;
  float: left;
}
ol.smaller-test-image {
  float: right;
}
li {
  margin: 0 30px 20px 0;
}

.original-image { height: auto }
.object-fit-fill { object-fit: fill }
.object-fit-contain { object-fit: contain }
.object-fit-cover { object-fit: cover }
.object-fit-none { object-fit: none }
.object-fit-scale { object-fit: scale-down }


// -----------------------------------------------
//   Styling a warning message, hiding it when support for object-fit is present 
// -----------------------------------------------

.warning { 
  color: red; 
  font-size: 200%;
}
@supports (object-fit: fill ) {
  .warning { display: none; }
}
            
          
!
999px
Loading ..................

Console