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>Float vs Flex vs Grid</h1>
<p>This example shows laying out 6 boxes in all three systems. In each system there is a 6 column layout with one row and a 3 column layout with two rows.</p>

<p>To see the difficulty of workign with both float and flex, as opposed to grid, try adding in 20px gap between columns and rows. Also try changing the number of columns and see how much work each takes. Again grid is MUCH simpler.</p>

<section class="float col-6">
  <header>
    <h2>Float: six column</h2>
   </header>
  
  <div class="box"><p>1</p></div>
  <div class="box"><p>2</p></div>
  <div class="box"><p>3</p></div>
  <div class="box"><p>4</p></div>
  <div class="box"><p>5</p></div>
  <div class="box"><p>6</p></div>
</section>

<section class="float col-3">
  <header>
    <h2>Float: 3 column</h2>
  </header>
  
  <div class="box"><p>1</p></div>
  <div class="box"><p>2</p></div>
  <div class="box"><p>3</p></div>
  <div class="box"><p>4</p></div>
  <div class="box"><p>5</p></div>
  <div class="box"><p>6</p></div>
</section>

<section class="flex col-6">
  <header>
    <h2>Flexbox: six column</h2>
   </header>
  
  <div class="flex-container">
    <div class="box"><p>1</p></div>
    <div class="box"><p>2</p></div>
    <div class="box"><p>3</p></div>
    <div class="box"><p>4</p></div>
    <div class="box"><p>5</p></div>
    <div class="box"><p>6</p></div>
  </div>
</section>

<section class="flex col-3">
  <header>
    <h2>Flexbox: 3 column</h2>
  </header>
  
  <div class="flex-container">
    <div class="box"><p>1</p></div>
    <div class="box"><p>2</p></div>
    <div class="box"><p>3</p></div>
    <div class="box"><p>4</p></div>
    <div class="box"><p>5</p></div>
    <div class="box"><p>6</p></div>
  </div>
</section>

<section class="grid col-6">
  <header>
    <h2>Grid: six column</h2>
   </header>
  
  <div class="grid-container">
    <div class="box"><p>1</p></div>
    <div class="box"><p>2</p></div>
    <div class="box"><p>3</p></div>
    <div class="box"><p>4</p></div>
    <div class="box"><p>5</p></div>
    <div class="box"><p>6</p></div>
  </div>
</section>

<section class="grid col-3">
  <header>
    <h2>Grid: 3 column</h2>
  </header>
  
  <div class="grid-container">
    <div class="box"><p>1</p></div>
    <div class="box"><p>2</p></div>
    <div class="box"><p>3</p></div>
    <div class="box"><p>4</p></div>
    <div class="box"><p>5</p></div>
    <div class="box"><p>6</p></div>
  </div>
</section>
              
            
!

CSS

              
                
/*
====================================
FLOAT
====================================
*/
.float.col-6 .box{
  float: left;
  width: 16.66666%; /* 100/6 = 16.666666 */
}

.float.col-3 .box{
  float: left;
  width: 33.33333%;/* 100/3 = 33.333333 */
}

section.float:after{
/*   Clearfix from: https://css-tricks.com/snippets/css/clear-fix/ */
  content: "";
  display: table;
  clear: both;
}

/*
====================================
FLEXBOX
====================================
*/
.flex-container{
  display: flex;
/*   justify-content: space-between; */
}

/* By default flex items are only as wide as their content so we need to add flex grow to each item so they will fill the space. Note, if tehre were more than 6 items, we would need to specify wrap and each item width to keep 6 columns (see 3 columns below). */
.col-6 .box{
  flex-grow: 1;
}

/* To get 3 columns and force the flex items into two rows we need to tell the flex container that it can wrap items. */
.col-3 .flex-container{
  flex-wrap: wrap;
}

/* Then we need to set a width on the items to get the 3 columns: 100/3 = 33.333333 */
.flex.col-3 .box{
  width:33.333333%; /* 100/3 = 33.333333 */
}

/*
====================================
GRID
====================================
*/
.grid-container {
  display: grid;
}

.col-6 .grid-container{
  grid-template-columns: repeat(6, 1fr);
}

.col-3 .grid-container{
  grid-template-columns: repeat(3, 1fr);
}





/*
====================================
GENERAL STYLING
These are just general styling that applies to the whole page. 
====================================
*/
section{
  margin: 3rem 0;
  clear:both;
}
section.col-6{
  margin-top: 6rem;;
}



.box{
  text-align: center;
  outline: 1px solid red;
}

body{
  font-family: sans-serif;
  line-height: 1.4;
}
              
            
!

JS

              
                
              
            
!
999px

Console