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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <!-- Side Nav -->
  <nav id="navbar">
    <header>
      CSS Flexbox
    </header>
    <ul>
      <li><a href="#display:_flex;" class="nav-link">display: flex;</a></li>
      <li><a href="#flex-direction:" class="nav-link">flex-direction:</a></li>
      <li><a href="#justify-content:" class="nav-link">justify-content:</a></li>
      <li><a href="#align-items:" class="nav-link">align-items:</a></li>
      <li><a href="#flex-wrap:" class="nav-link">flex-wrap:</a></li>
    </ul>
  </nav>
  <main id="main-doc">
    <section class="main-section" id="display:_flex;">
      <header>
        display: flex;
      </header>
      <div class="spacer"></div>
      <div class="section-inner">
        <p><code>display: flex;</code> instructs the browser to convert a <code>div</code> element into a flex container. <br> Look at the following example:</p>

        <p>CSS code:</p>
        <div class="code-block">
          <code>
            <span class="css-selector">.container</span> {<br>
              &nbsp; <span class="tag">display:</span> <span class="css-attribute">flex;</span><br>
            } <br>
          </code>
        </div>
        <br>
        <p>HTML code:</p>
        <div class="code-block">
          <code>
            <span class="tag">&lt;div class="<span class="css-attribute">container</span>"></span><br>
            &nbsp; This is a flex container <br>
            <span class="tag">&lt;/div></span> 
          </code>
        </div>
        </div>
    </section>
    <section class="main-section" id="flex-direction:">
      <header>
        flex-direction:
      </header>
      <div class="spacer"></div>
      <div class="section-inner">
        <p>The flex direction determines the direction of the main and cross axes.</p>
        <p>This can be a little confusing, as when the desired result is two columns, you will set the <code>flex-direction</code> to <code>row</code> so that the element can be divided horizonatally. Conversely, setting <code>flex-direction: column;</code> will set a vertical main axis, and items will be added along it.<br>
        The following code creates a 50-50 horizontal split of the flex container.</p> 
          <p>CSS code:</p>
          <div class="code-block">
            <code>
             <span class="css-selector">.container</span> {<br>
                &nbsp; <span class="tag">display</span>: <span class="css-attribute">flex</span>;<br>
                &nbsp; <span class="tag">flex-direction</span>: <span class="css-attribute">row</span>;<br>
                &nbsp; <span class="tag">width</span>: <span class="css-attribute">100vw</span>;<br>
              } <br>
              <span class="css-selector">.col</span> {<br>
                &nbsp; <span class="tag">width</span>: <span class="css-attribute">50%</span>;<br>
              }<br>
              <span class="css-selector">.left-col</span> {<br>
              &nbsp; <span class="tag">background</span>: <span class="css-attribute">yellow</span>;<br>
            }<br>
            <span class="css-selector">.right-col</span> {<br>
              &nbsp; <span class="tag">background</span>: <span class="css-attribute">blue</span>;<br>
            }
            </code>
          </div><br><br>
          <p>HTML code:</p>
          <code>
            &lt;div class="container"><br>
            &nbsp; &lt;div class="col left-col"><br>
            &nbsp; &nbsp; Left column<br> 
            &nbsp; &lt;/div><br>
            &nbsp; &lt;div class="col right-col"><br>
            &nbsp; &nbsp; Right column<br> 
            &nbsp; &lt;/div><br>
            &lt;/div>
          </code>
          </div>
     </section>
     <section class="main-section" id="justify-content:">
        <header>
          justify-content:
        </header>
        <div class="spacer"></div>
        <div class="section-inner">
        <p><code>justify-content:</code> aligns flex items along the main axis. The items can be aligned using the following attributes:</p>
        
        <ul>
          <li><code>flex-start</code> - aligns items to the left of the container</li>
          <li><code>center</code> - centers the items horizonatally</li>
          <li><code>flex-end</code> - aligns the items to the right of the container</li>
          <li><code>space-between</code> - calculates space between each flex item and pushes the outermost items to the container's edges.</li>
          <li><code>space-around</code> - similar to space between, but also adds space between the outermost items and the edges.</li>
          <li><code>self</code> - allows alignment of a single element</li>
        </ul>
        </div>
     </section>
     <section class="main-section" id="align-items:">
      <header>
        align-items:
      </header>
      <div class="spacer"></div>
      <div class="section-inner">
      <p><code>align-items:</code> aligns flex items along the cross axis. The items can be aligned using the following attributes:</p>
      
      <ul>
        <li><code>flex-start</code> - aligns items to the top of the container</li>
        <li><code>center</code> - centers the items vertically</li>
        <li><code>flex-end</code> - aligns the items to the bottom of the container</li>
        <li><code>space-between</code> - calculates space between each flex item and pushes the outermost items to the container's vertical edges.</li>
        <li><code>space-around</code> - similar to space between, but also adds space between the outermost items and the vertical edges.</li>
        <li><code>self</code> - allows alignment of a single element</li>
      </ul>
      </div>
   </section>
   <section class="main-section" id="flex-wrap:">
    <header>
      flex-wrap:
    </header>
    <div class="spacer"></div>
    <div class="section-inner">
    <p><code>flex-wrap:</code> forces flex items to <em>wrap</em> onto a new row if there is no more room in the viewport. This property can be used is some cases to avoid the use of breakpoints.</p>
    
    <p>Without <code>flex-wrap: wrap;</code> the flex items would continue to be squashed as the viewport size shrinks.</p>
    </div>
 </section>     
  </main>

  <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script> 
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
   font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
}
nav {
  float: left;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 300px;
  background: rgb(205, 255, 212);
  box-shadow: 5px 5px 5px #777777;
}
.nav-div {
  border-top: solid 2px #723700;
 
}
#navbar ul {
  list-style-type: none;
  display: flex;
  flex-direction: column;
}
#navbar ul li {
  border-top: solid 1px #723700;
}
.nav-link {
  display: block;
  padding: 10px;
  text-decoration: none;
  color: #3f1e00;
  transition: all .7s;
}
.nav-link:hover {
  background: yellow;
}
main {
  margin-left: 290px;
  transition: all 0.5s;
}
header {
  font-size: 1.5em;
  font-weight: 400;
  width: 100%;
  background: linear-gradient(90deg, #ffa44e, 25%, rgba(255, 255, 255, 0));
  padding: 5px 15px;
  margin-top: 25px;
}
.main-section {
  margin-left: 30px;
}
.main-section ul {
  margin-left: 15px;
}
.spacer {
  height: 10px;
}
code {
  font-size: 1.1em;
  font-family: 'Courier New', Courier, monospace;
  color: rgb(0, 75, 160);
}

p {
  margin-bottom: 10px;
}
.section-inner {
  background: #dddddd;
  border: solid 5px #777777;
  padding: 5px;
  box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.7);
  width: 70%;
  overflow: auto;
}
.code-block {
  background: #2b2b2b;
  width: max-content;
  max-height: 400px;
  overflow: auto;
  border-radius: 3px;
  padding: 5px;
  margin: 0 5px 0 5px;
}
.code-block code { 
  color: rgb(201, 201, 201);
  font-size: 1.1em;
  font-family: 'Courier New', Courier, monospace;
}
.tag {
  color: rgb(255, 235, 119);
}
.css-selector {
  color: rgb(255, 152, 255);
}
.css-attribute {
  color: rgb(168, 198, 255);
}
@media screen and (max-width: 800px) {
  nav {
    transform: translateX(-293px);
    transition: all 0.5s;
    animation: inout 10s infinite;
  }
  @keyframes inout {
    50% {
      background-color: red;
    }
  }
  nav:hover {
    transform: translateX(0);
    animation: inout none;
    opacity: 0.85;
    cursor: pointer;
  }
  main, .main-section { 
    margin: 0;
  }
  #main-doc {
    width: 95%;
  }
  .section-inner {
    width: 100%;
  }
}
@media screen and (max-width: 1000px) {
  main {
    width: 85%;
  }
}
              
            
!

JS

              
                
              
            
!
999px

Console