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 class="Center-Container">
</div>-->

  <div class="Absolute-Center Center-Block">
    <strong class="Title">Absolute Center, Fit-Content.</strong><br />
    I'm multi-line, and it's no big deal.<br />
    I adjust to whatever the content width or height is.
  </div>
<div id="Test"></div>
            
          
!
            
              #Test { font-size: 0.1px; line-height: 0.1px; width: 100px; height: 100px; width: -moz-fit-content; width: -webkit-fit-content; width: fit-content; height: -moz-fit-content; height: -webkit-fit-content; height: fit-content; background: red; opacity: 0.5; overflow: hidden; }

/*
////////////////////////////////////////
 Absolute Centering
//////////////////////////////////////// 
*/
.Absolute-Center { 
  width: 50%; /* Fallback */
  width: -moz-fit-content;
  width: -webkit-fit-content;
  width: fit-content;

  height: 50%; /* Fallback */
  height: -moz-fit-content;
  height: -webkit-fit-content;
  height: fit-content;
  
  overflow: auto; /* Recommended in case content is larger than the container */
  margin: auto; /* Center the item vertically & horizontally */
  position: absolute; /* Break it out of the regular flow */
  top: 0; left: 0; bottom: 0; right: 0; /* Set the bounds in which to center it, relative to its parent/container */
}
/*
@supports (height: -webkit-fit-content) {
  .Absolute-Center { 
    display: block;
    height: -webkit-fit-content;
    background: red !important;
  }
}*/


/* 
////////////////////////////////////////
 Presentational Code. You can ignore this!
//////////////////////////////////////// 
*/

@green: #4fa46b;
@greenDark: #2e5f3e;

// Demos
.Center-Container { background: @greenDark; color: @green; width: 100%; height: 400px; margin: 20px auto 40px; clear: both; }
.Center-Block { background: @green; color: #FFF; padding: 20px; }
.Center-Block .Title { padding: 0; margin: 0 0 .5em; line-height: 1em; }
            
          
!
            
              Modernizr.testStyles('#modernizr { font-size: 0.1px; line-height: 0.1px; width: 100px; height: 100px; width: -moz-fit-content; width: -webkit-fit-content; width: fit-content; height: -moz-fit-content; height: -webkit-fit-content; height: fit-content; }', function(elem, rule) {
  Modernizr.addTest('fitcontentheight', elem.offsetHeight === 0);
  Modernizr.addTest('fitcontentwidth', elem.offsetWidth === 0 ); 
  console.log("#Modernizr width ",elem.offsetWidth," height ",elem.offsetHeight);

});

/* Check error console. Width and Height should return `0` */
var elem = document.getElementById("Test");
console.log("Width and Height should be `0` if browser supports `fit-content` correctly:");
console.log("Test Element: width ",elem.offsetWidth," height ",elem.offsetHeight);
            
          
!
999px
Loading ..................

Console