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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<nav id = "navbar">
      <header>CSS Flexbox</header>
      <ul>
        <li><a class = "nav-link" href = "#What_is_Flexbox">What is Flexbox</a></li>
        <li><a class = "nav-link" href = "#Why_use_Flexbox">Why use Flexbox</a></li>
        <li><a class = "nav-link" href = "#How_to_apply_Flexbox">How to apply Flexbox</a></li>
        <li><a class = "nav-link" href = "#Flexbox_Elements">Flexbox Elements</a></li>
        <li><a class = "nav-link" href = "#Flexbox_Properties">Flexbox Properties</a></li>
        <li><a class = "nav-link" href = "#Examples">Examples</a></li>
        <li><a class = "nav-link" href = "#References">References</a></li>
      </ul>
    </nav>
    <main id = "main-doc">
      <section class = "main-section" id = "What_is_Flexbox">
        <header>What is Flexbox</header>
        <article>
          <p>Introduced in CSS3, The flexbox Layout (Flexible Box) module is an efficient way to lay out items, align the items and space out items regardless of the sizing of the items-- in other words, make the items "flexible".</p>
          <p>This module was added to give the container the ability to change the size of the items to fill in the free space where needed on all screen sizes.</p>
        </article>
      </section>
      <section class = "main-section" id = "Why_use_Flexbox">
        <header>Why use Flexbox</header>
        <article>
          <p>The Flexbox module has significant advantages over previous CSS modules.</p>
          <ul>
            <li>Flex containers fill up free space by expanding items or shrink them to avoid overflow of items.</li>
            <li>Avoids the need of JavaScript to create certain design patterns.</li>
            <li>Makes items in the container "flexible" without the need for float or positioning.</li>
          </ul>
        </article>
      </section>
      <section class = "main-section" id = "How_to_apply_Flexbox">
        <header>How to apply Flexbox</header>
        <article>
          <p>To apply flexbox onto a container of items, select the container you want to use flexbox on and set the <u>display</u> property to <em><b>flex</b></em>:</p>
          <code>.container {
              display: flex;
            }</code>
          <p>Once the <u>display</u> property is set, you can change the flexbox properties for the container.</p>
        </article>
      </section>
      <section class = "main-section" id = "Flexbox_Elements">
        <header>Flexbox Elements</header>
        <article>
          <img src = "https://css-tricks.com/wp-content/uploads/2018/11/00-basic-terminology.svg" alt= "Flexbox Elements">
          <p>There are two main elements to consider when using flexbox on your style sheets:</p>
          <ul>
            <li>Flex container: a block element (usually a div element) that contains the items that will use flexbox.</li>
            <li>Flex item: a block of text or a block element made "flexible" along the boundaries of the container.</li>
          </ul>
          <p>Here's an example of how flex containers and flex items are written in HTML:</p>
          <code>&lt;div class = "container"&gt;<br>
              &lt;div&gt;1&lt;/div&gt;<br>
              &lt;div&gt;2&lt;/div&gt;<br>
              &lt;div&gt;3&lt;/div&gt;<br>
            &lt;/div&gt;
          </code>
          <p>There are two axes to consider when using flexbox on block elements: the main (horizontal) axis and the cross (vertical) axis.</p>
        </article>
      </section>
      <section class = "main-section" id = "Flexbox_Properties">
        <header>Flexbox Properties</header>
        <article>
          <p>There are a list of properties you can be able to change using CSS to add custom "flexibility" to both the parent and child elements.</p>
          <p><b>Properties for Parent Elements</b></p>
          <ul>
            <li><u>flex-direction</u>: determines if the main axis will line up the items in a row or column.</li>
            <li><u>flex-wrap</u>: determines how the items will wrap in the container when overflows occurs.</li>
            <li><u>flex-flow</u>: shorthand property to set both <code>flex-direction</code> and <code>flex-wrap</code> properties.</li>
            <li><u>justify-content</u>: determines the alignment of items along the main axis and the distribution of space between items.</li>
            <li><u>align-items</u>: determines the alignment of items along the cross axis.</li>
            <li><u>align-content</u>: determines the alignment of the flex containers lines along the cross axis.</li>
          </ul>
          <p><b>Properties for Child Elements</b></p>
          <ul>
            <li><u>order</u>: determines the order of the flex items in the container.</li>
            <li><u>flex-grow</u>: determines how much the item grows, relative to the other items, as the container grows.</li>
            <li><u>flex-shrink</u>: determines how much the item shrinks by.</li>
            <li><u>flex-basis</u>: specifies the initial length of the flex item.</li>
            <li><u>flex</u>: shorthand property to set the <code>flex-grow</code>, <code>flex-shrink</code>, and <code>flex-basis</code> properties</li>
            <li><u>align-self</u>: specifies and overrides the alignment of selected flex items.</li>
          </ul>
        </article>
      </section>
      <section class = "main-section" id = "Examples">
        <header>Examples</header>
        <article>
          <h3>Example #1: Stretched Middle, fixed spacing</h3>
          <code>.container {
                  display: flex;
                }

                .item {
                  height: 100px;
                  width: 100px; /* A fixed width as the default */
                }

                .item-center {
                  flex-grow: 1; /* Set the middle element to grow and stretch */
                }

                .item + .item {
                  margin-left: 2%;
                }
          </code>
          <h3>Example #2: Alternating Grid</h3>
          <code>.container {
              display: flex;
              flex-wrap: wrap;
              justify-content: space-between;
            }

            .item {
              width: 48%;
              height: 100px;
              margin-bottom: 2%;
            }

            .item:nth-child(3n) {
              width: 100%;
            }
          </code>
          <h3>Example #3: Vertical Stack</h3>
          <code>.container {
              display: flex;
              flex-direction: column;
              align-items: center;
            }

            .item {
              height: 40px;
              margin-bottom: 10px;
            }
          </code>
          </article>
      </section>
      <section class = "main-section" id = "References">
        <header>References</header>
        <p><a href = "https://css-tricks.com/snippets/css/a-guide-to-flexbox/">CSS Tricks</a></p>
        <p><a href = "https://www.w3schools.com/css/css3_flexbox.asp">W3 Schools</a></p>
        <p><a href = "https://tobiasahlin.com/blog/common-flexbox-patterns/">Tobias Ahlin</a></p>
      </section>
    </main>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;0,800;1,300;1,400;1,600;1,700;1,800&display=swap');

      body {
        background-color: #f5f5f5;
        font-family: "Open Sans", Arial, sans-serif;
        line-height: 1.5;
        margin-top: 300px;
      }
      #navbar {
        position: absolute;
        top: 0;
        padding: 0;
        margin: -8px;
        width: 100%;
        max-height: 280px;
        border: none;
      }
      header {
        margin-top: 15px;
        text-align: center;
        font-size: 2.0em;
      }
      img {
        width: 600px;
      }
      #navbar ul {
        height: 200px;
        padding: 0;
        overflow-y: auto;
        overflow-x: hidden;
        border: 2px solid;
      }
      #navbar li {
        border-bottom: 1px solid;
        list-style: none;
        position: relative;
        width: 100%;
      }
      #navbar a {
        display: block;
        color: black;
        padding: 10px 20px;
        text-decoration: none;
        cursor: pointer;
      }
      #main-doc {
        position: absolute;
        padding-left: 20px;
        padding-bottom: 100px;
        padding-right: 30px;
      }
      #main-doc header {
        text-align: left;
        margin: 0;
      }
      #How_to_apply_Flexbox code {
        display: block;
        margin-right: 20px;
      }
      #Flexbox_Elements code {
        padding: 10px;
        display: block;
        margin-right: 20px;
      }
      #Examples code {
        margin-bottom: 25px;
        padding: 15px;
        display: block;
        margin-right: 20px;
      }
      section {
        margin-top: 50px;
      }
      article {
        margin-left: 25px;
      }
      code {
        padding: 5px;
        background-color: #dcdcdc;
        word-break: normal;
        word-wrap: normal;
        text-align: left;
        white-space: pre-line;
        position: relative;
      }
      @media only screen and (min-width: 815px) {
        body {
          margin-top: 0px;
        }
        #navbar {
          position: fixed;
          width: 300px;
          top: 0px;
          left: 0px;
          height: 100%;
          z-index: 1;
          max-height: none;
        }
        #navbar ul {
          height: 100%;
        }
        #main-doc {
          position: absolute;
          margin-left: 282px;
          border-left: 2px solid;
        }
        section {
          margin-left: 15px;
        }
        #What_is_Flexbox {
          margin-top: 25px;
        }
        #How_to_apply_Flexbox code {
          margin-right: 60%;
        }
        #Flexbox_Elements code {
          margin-right: 60%
        }
        #Examples code {
          margin-right: 60%;
        }
      }
              
            
!

JS

              
                
              
            
!
999px

Console