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

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

              
                <h1>Flexbox layout patterns.</h1>
<p>Keep a simple dom structure. No wrapper for Flexbox.</p>
<section class="HolyGrail">
 <header><h2>Holy Grail</h2>header</header>
 <main>main</main>
 <nav>nav</nav>
 <aside>aside</aside>
 <footer>footer</footer>
</section>
<section class="sideways">
 <header><h2>Lay "Holy Grail" down on side.</h2>header</header>
 <main>main</main>
 <nav>nav</nav>
 <aside>aside</aside>
 <footer>footer</footer>
</section>
<section class="oneColumn">
 <header><h2>One Column.</h2>header</header>
 <main>main</main>
 <nav>nav</nav>
 <aside>aside</aside>
 <footer>footer</footer>
</section>
<section class="horizontalNav">
 <nav>
  <h2>Horizontal nav.</h2>
  <ul>
   <li><a href="#">link</a></li>
   <li><a href="#">link</a></li>
   <li><a href="#">link</a></li>
   <li><a href="#">link</a></li>
   <li><a href="#">link</a></li>
   <li><a href="#">link</a></li>
   <li><a href="#">link</a></li>
  </ul>
 </nav>
</section>
<section class="grid">
 <h2>Grid <small>space-between and psuedo trick makes nicely last row.</small></h2>
 <ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
 </ul>
 <ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
 </ul>
 <ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
 </ul>
</section>
<section class="masonry">
 <h2>Masonry</h2>
 <ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
  <li>6</li>
  <li>7</li>
  <li>8</li>
  <li>9</li>
  <li>10</li>
  <li>11</li>
  <li>12</li>
 </ul>
</section>
<section class="masonry-v">
 <h2>Masonry (virtical)</h2>
 <ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
  <li>6</li>
  <li>7</li>
  <li>8</li>
  <li>9</li>
  <li>10</li>
  <li>11</li>
  <li>12</li>
 </ul>
</section>
              
            
!

CSS

              
                body > * {
 width: 30rem;
 margin: 2rem auto;
}
section {
 display: flex;
}
section > * {
 padding:1em;
 box-sizing: border-box;
}
header {
 background-color: hsl(0,100%,80%);
 order: 1;
}
footer {
 background-color: hsl(72,70%,80%);
 order: 5;
}
main   {
 background-color: hsl(144,70%,80%);
 order: 3;
}
nav    {
 background-color: hsl(216,70%,80%);
 order: 2;
}
aside  {
 background-color: hsl(288,70%,80%);
 order: 4;
}

.HolyGrail {
 flex-direction: row;
 flex-wrap: wrap;
}
.HolyGrail header,
.HolyGrail footer {
 flex-basis: 100%;
}
.HolyGrail main {
 flex-grow: 1;
}
.HolyGrail nav {
 flex-basis: 25%;
}
.HolyGrail aside {
 flex-basis: 25%;
}

.sideways {
 flex-direction: column;
 flex-wrap: wrap;
 height: 16em;
}
.sideways main,
.sideways nav,
.sideways aside {
 flex-basis: 20%;
 width: 40%;
}
.sideways main {
 flex-grow: 1;
}
.sideways footer {
 flex-basis: 100%;
 width: 20%;
}
.sideways header {
 width: 40%;
 flex-basis: 100%;
}
.oneColumn {
 flex-direction: column;
 flex-wrap: nowwrap;
}

.horizontalNav {
 display: block;
}
.horizontalNav nav {
 display: block;
}
.horizontalNav ul {
 display: flex;
 justify-content: space-between;
 list-style: none;
 padding-left: 0;
 background-color: rgba(0,0,0,0.1);
}
.horizontalNav li {
 flex-basis: auto;
}
.horizontalNav a {
 text-decoration: none;
 padding: 0.5em 1em;
 background-color: rgba(0,0,0,0.3);
 color: #fff;
 display: block;
}
.grid {
 display: block;
 background-color: #ccc;
 padding-bottom: 0.1em;
}
.grid > h2 {
 padding: 2rem 1rem 1rem;
 margin-bottom: 0;
}
.grid ul {
 display: flex;
 list-style: none;
 flex-flow: row wrap;
 justify-content: space-between;
 background-color: rgba(0,100,0,0.2);
 margin: 0 1em 2em;
 align-content: space-between;
 padding-bottom: 0;
}
.grid ul > * {
 flex-basis: 32%;
 max-width: 32%; /* IE11 bugfix */
 background-image: linear-gradient(45deg,#888,#333);
 height: 4em;
 margin-bottom: 1em;
 background-position: 0 0;
 box-sizing: border-box;
 padding: 0.5em;
 color: #fff;
}
/* psuedo trick. */
.grid ul::after {
 content: "";
 flex-basis: 32%;
 background-color: rgba(200,0,0,0.3);
 display: block;
 height: 0;
}
.grid ul li:last-of-type:nth-of-type(3n) {
 margin-right: -34%;
}
.masonry {
 display: block;
 background-color: #ecc;
 padding-bottom: 0.1em;
}
.masonry > h2 {
 padding: 2rem 1rem 1rem;
 margin-bottom: 0;
}
.masonry ul {
 display: flex;
 flex-flow: row wrap;
 list-style: none;
 justify-content: space-between;
 background-color: rgba(50,100,0,0.2);
 margin: 0 1em 2em;
}
.masonry ul > * {
 flex-basis: 20%;
 background-image: linear-gradient(45deg,#a88,#633);
 height: 4em;
 flex-grow: 1;
 margin: 1px;
 box-sizing: border-box;
 padding: 0.5em;
 color: #fff;
}
.masonry ul > :nth-of-type(2n+1) {
 flex-basis: 30%;
}
.masonry-v {
 display: block;
 background-color: #ecc;
 padding-bottom: 0.1em;
}
.masonry-v > h2 {
 padding: 2rem 1rem 1rem;
 margin-bottom: 0;
}
.masonry-v ul {
 display: flex;
 flex-flow: row wrap;
 list-style: none;
 justify-content: space-between;
 background-color: rgba(50,100,0,0.2);
 margin: 0 1em 2em;
 padding-bottom: 3em;
}
.masonry-v ul > * {
 flex-basis: calc(50% - 2px);
 max-width: calc(50% - 2px); /* IE11 bugfix */
 background-image: linear-gradient(45deg,#a88,#633);
 height: 4em;
 margin: 1px;
 box-sizing: border-box;
 padding: 0.5em;
 color: #fff;
}
.masonry-v ul > :nth-of-type(2n) {
 transform: translateY(50%);
}
              
            
!

JS

              
                
              
            
!
999px

Console