Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                <div class="legend">
  <h2>Legend</h2>
  <div><div class="legend__padding"></div>padding-box</div>
  <div><div class="legend__content"></div>content-box</div>
</div>

<h2 class="heading">Flex-basis: 0 and flex item with padding </h2>
<div class="container">
  <div class="item flex-2">
    <h3>flex-grow: 2;</h3>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facere labore, odit fuga itaque neque in, laboriosam distinctio quos molestiae quibusdam a vero delectus dolorem ab ullam rerum culpa iusto veritatis.</p></div>
  <div class="item flex-3 bg-dark padding">
    <h3>flex-grow: 3;</h3>
    Lorem</div>
<div class="item flex-1"><h3>flex-grow: 1;</h3>Lorem isum sit dolor amet</div>
</div>

<h2 class="heading">Flex-basis: 0 and flex item without padding </h2>
<div class="container">
  <div class="item flex-2">
    <h3>flex-grow: 2;</h3>
    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facere labore, odit fuga itaque neque in, laboriosam distinctio quos molestiae quibusdam a vero delectus dolorem ab ullam rerum culpa iusto veritatis.</div>
  <div class="item flex-3 bg-dark"><div class="padding"><h3>flex-grow: 3;</h3>Lorem</div></div>
<div class="item flex-1"><h3>flex-grow: 1;</h3>Lorem isum sit dolor amet</div>
</div>

<h2 class="heading">Flex-basis: auto</h2>
<div class="container flex-auto">
  <div class="item flex-2">
    <h3>flex-grow: 2;</h3>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facere labore, odit fuga itaque neque in, laboriosam distinctio quos molestiae quibusdam a vero delectus dolorem ab ullam rerum culpa iusto veritatis.</p></div>
  <div class="item flex-3 bg-dark">
    <h3>flex-grow: 3;</h3>
    Lorem</div>
<div class="item flex-1"><h3>flex-grow: 1;</h3>Lorem isum sit dolor amet</div>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  font-family: sans-serif;
}

.legend {
  width: 600px;
  margin: 1rem auto;
  background: rgba(89, 190, 205, 0.2);
}

.legend > div {
  display: flex;
  align-items: center;
}

.legend__padding {
  width: 3rem;
  height: 1.5em;
  display: inline-block;
  margin-right: 1rem;
  background: repeating-linear-gradient(-45deg, rgba(50, 127, 190, 0.6), rgba(50, 127, 190, 0.6) 2px, transparent 2px, transparent 5px);
}

.legend__content {
  width: 3rem;
  height: 1.5em;
  display: inline-block;
  margin-right: 1rem;
  background: rgba(89, 190, 205, 0.5);
}

.heading {
  margin-top: 2rem;
  margin-bottom: 0;
  width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.container {
  display: flex;
  width: 600px;
  margin: 1rem auto;
  background: rgba(89, 190, 205, 0.2);
}

.item {
  flex-basis: 0;
  flex-shrink: 1;
  box-sizing: border-box;
}

.flex-auto > .item {
  flex-basis: auto;
}

.flex-1 {
  flex-grow: 1;
}

.flex-2 {
  flex-grow: 2;
}

.flex-3 {
  flex-grow: 3;
}

.bg-dark {
  position: relative;
  background: rgba(89, 190, 205, 0.5);
  background-clip: content-box;
}

.bg-dark:before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(-45deg, rgba(50, 127, 190, 0.6), rgba(50, 127, 190, 0.6) 2px, transparent 2px, transparent 5px);
}

.padding {
  /* 
  Padding increases the hypothetical main size of the flex item which gets subtracted from the remaining free space distributed by the flexbox algorithm. This means flex items will not completely match the flex-grow ration.
  
  To avoid this, define borders and padding on a child of the flex item.
  
  To read more about flexbox algorithm see the psecification: https://www.w3.org/TR/css-flexbox-1/#layout-algorithm
  */
  padding: 0 2rem;
}
              
            
!

JS

              
                
              
            
!
999px

Console