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.

              <h2>No width specified on child so expands to fill parent width but applied padding and border are moved inwards, happy days.</h2>
<div class="parent">
  <div class="child">

<h2>But now for whatever reason I need to specify a width on my child element. Buggery my child has broken out.</h2>

<div class="parent">
  <div class="child withWidth">

<h2>I could adjust my child width but I need it be a %, this won't work mixed with pixel padding and borders - CSS box-sizing to the rescue!</h2>

<div class="parent">
  <div class="child withWidth boxPower">

<h2>And we're back to the original (desired) outcome but with an explicit % width mixed with pixel based padding and borders. Happy Days!</h2>

<h3>Now read these for the background...</h3>

  <li><a href="http://paulirish.com/2012/box-sizing-border-box-ftw/">http://paulirish.com/2012/box-sizing-border-box-ftw/</a></li>
  <li><a href="https://css-tricks.com/box-sizing/">https://css-tricks.com/box-sizing/</a></li>
  <li><a href="http://html5please.com/#box-sizing">http://html5please.com/#box-sizing</a></li>

              .parent{background: #ccc; width: 800px; padding: 20px 0;}
.child{background: #eee; padding: 50px; border: solid 1px #111;}

/* But now for whatever reason I need to specify a width on my child element... */
.withWidth{width: 100%;}

/* CSS box-sizing to the rescue! */
.boxPower{-webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;}

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.


Loading ..................