Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              <h2>Understanding the CSS box-sizing property values</h2>
<div class="grid-container">
   <div id="div1" class="container div-1">
      <div><strong>box-sizing: content-box</strong>      
      </div>
      <div class="info"></div>
   </div>

   <div>
      By default <code>box-sizing: content-box</code> is active. This means that an element's assigned  width applies only to its content. Any padding and border widths added increase the overall element width. The width of blue box's to the left is set to 400px, but its padding and border widths make the total width of the element 426px. This can be a frustrating "feature" when desigining UIs. 
   </div>   
</div>   

<hr>

<div class="grid-container">
   <div class="container div-2">
      <div><strong>box-sizing: border-box</strong>
      </div>   
      <div class="info"></div>
   </div>
   <div>
      CSS3 introduced the <code>box-sizing: border-box</code> property. When this property is active an element's specified width is guaranteed to include any padding and border width assigned.    The width of blue box's to the left is set to 400px and that width includes its padding and border widths--making its total width be exactly as specified, 400px. Most CSS resets and CSS frameworks assign this property. <code>box-sizing: border-box</code> is available <a href="https://caniuse.com/#search=border-box">on virtually every browser.</a> 
   </div>   
</div>   

            
          
!

CSS

            
              body {
  font-family: Sans-Serif;
}

.grid-container {
   display: grid;
   grid-template-columns: 450px auto;
   justify-items: start;
}

.container {
   border: 8px solid red;
   padding: 5px;
   background-color: blue;
   width: 400px;
   color: #fff;
}

.div-1 {
   /* This is the default  */
   box-sizing: content-box;      
}

.div-2 {
   box-sizing: border-box;      
}
            
          
!

JS

            
              const removeNonNumericChars = function(value) {
   return parseInt(value.replace(/\D/g,''), 10);
}

const getWidthHeight = function(element) {
   let outerWidth = element.offsetWidth;   
   let height = element.offsetHeight;   
      
   let info = element.querySelector('.info');   
   let innerWidth = parseInt(element.clientWidth,10);
   let paddingLeft = window.getComputedStyle(element, null).getPropertyValue('padding-left');
   let paddingRight = window.getComputedStyle(element, null).getPropertyValue('padding-right');
   let borderLeft = window.getComputedStyle(element, null).getPropertyValue('border-left-width');
   let borderRight = window.getComputedStyle(element, null).getPropertyValue('border-right-width');
   let contentWidth = outerWidth - 
                      removeNonNumericChars(paddingLeft) - 
                      removeNonNumericChars(paddingRight) - 
                      removeNonNumericChars(borderLeft) -
                      removeNonNumericChars(borderRight);
   
   info.innerHTML = `outer width: ${outerWidth} <br>\
                     inner width ${innerWidth} <br>\ 
                     content-only width: ${contentWidth}<br>\
                     padding width left: ${paddingLeft}<br>\
                     padding width right: ${paddingRight}<br>\
                     border width left: ${borderLeft}<br>\
                     border width right: ${borderRight}<br>`;        
}

getWidthHeight(document.querySelector('.div-1'));
getWidthHeight(document.querySelector('.div-2'));
            
          
!
999px

Console