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.

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

              
                <main>
  <h2>Dimensions of Elements with Transforms<br>vs. Elements without Transforms</h2>

  <p>When elements have transforms applied, their dimension values might be affected, depending on the DOM method/property used. All four boxes below have dimension of 160px x 160px in the CSS. The first box is scaled down, the second box is skewed, the third box is moved via translate, and the fourth box is rotated.</p>

  <div class="boxes">
    <div class="box box1">scale()</div>
    <div class="box box2">skew()</div>
    <div class="box box3">translate()</div>
    <div class="box box4">rotate()</div>
  </div>
  
  <p>Use the buttons below to display the dimensions of all the boxes via <code>getBoundingClientRect()</code> and <code>offsetWidth/Height</code></p>
  
  <p class="btns">
    <button>Get Dimensions with getBoundingClientRect()</button>
    <button>Get Dimensions with offsetWidth/Height</button>
  </p>

  <output></output>

</main>
              
            
!

CSS

              
                body {
  font-family: Arial, sans-serif;
  font-size: 20px;
  padding: 0 20px;
}

main {
  text-align: center;
  margin: 0 auto;
  max-width: 800px;
}

.boxes {
  display: flex;
  justify-content: space-around;
  padding: 0 40px 20px 40px;
}

p {
  text-align: left;
  padding: 0 20px;
}

code {
  color: firebrick;
}

.box {
  width: 160px;
  height: 160px;
  line-height: 7;
}

.box1 {
  background: lightblue;
  transform: scale(0.8);
}

.box2 {
  background: lightgreen;
  transform: skew(10deg);
}

.box3 {
  background: thistle;
  transform: translate(20px, 20px);
}

.box4 {
  background: burlywood;
  transform: rotate(45deg);
}

output {
  display: block;
  margin-top: 20px;
  line-height: 1.4;
}

.btns {
  text-align: center;
}

button {
  margin-top: 16px;
}
              
            
!

JS

              
                let box1 = document.querySelector('.box1'),
    box2 = document.querySelector('.box2'),
    box3 = document.querySelector('.box3'),
    box4 = document.querySelector('.box4'),
    op = document.querySelector('output'),
    btn1 = document.querySelector('button'),
    btn2 = document.querySelectorAll('button')[1];

btn1.addEventListener('click', function () {
  op.innerHTML = `
    <b>Box 1:</b> ${box1.getBoundingClientRect().width} x 
       ${box1.getBoundingClientRect().height}<br>
    <b>Box 2:</b> ${box2.getBoundingClientRect().width} x 
       ${box2.getBoundingClientRect().height}<br>
    <b>Box 3:</b> ${box3.getBoundingClientRect().width} x 
       ${box3.getBoundingClientRect().height}<br>
    <b>Box 4:</b> ${box4.getBoundingClientRect().width} x 
       ${box4.getBoundingClientRect().height}<br>
  `;
}, false);

btn2.addEventListener('click', function () {
  op.innerHTML = `
    <b>Box 1:</b> ${box1.offsetWidth} x ${box1.offsetHeight}<br>
    <b>Box 2:</b> ${box2.offsetWidth} x ${box2.offsetHeight}<br>
    <b>Box 3:</b> ${box3.offsetWidth} x ${box3.offsetHeight}<br>
    <b>Box 4:</b> ${box4.offsetWidth} x ${box4.offsetHeight}<br>
  `;
}, false);


    
              
            
!
999px

Console