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 Grid</header>
  <a href="#About_CSS_Grid" class="nav-link">About CSS Grid</a>
  <a href="#Make_a_Grid" class="nav-link">Make a Grid</a>
  <a href="#Adding_Columns_and_Rows" class="nav-link">Adding Columns and Rows</a>
  <a href="#Creating_Gaps" class="nav-link">Creating Gaps</a>
  <a href="#Area_Templates" class="nav-link">Area Templates</a>
</nav>
<main id="main-doc">
  <section class="main-section" id="About_CSS_Grid">
    <header>About CSS Grid</header>
    <p>CSS Grid Layout is arguably the most powerful layout system available in CSS. It is a two-dimensional system, meaning it can handle both columns and rows. This is unlike flexbox, which is viewed as a one-dimensional system. You work with Grid Layout by applying CSS rules both to a parent element (which becomes the Grid Container) and to that element’s children (which become Grid Items).</p>
  </section>
  <section class="main-section" id="Make_a_Grid">
    <header>Make a Grid</header>
    <p>Turn any HTML element into a grid by simply setting <code>display</code> to <code>grid.</code></p>
    <code class="code-block">display: grid</code>
    <p>This is similar to how we can change elements to <code>flexbox.</code></p>
  </section>
  <section class="main-section" id="Adding_Columns_and_Rows">
    <header>Adding Columns and Rows</header>
    <p>After adding the grid, define the structure. To add columns, use <code>grid-template-columns</code> on a grid container as below:</p>
    <pre><code class="code-block">display: grid;
grid-template-columns: 50px 50px 50px;</code>
      </pre>
    <p>This gives three columns that are 50px each. The number of parameters given to the <code>grid-template-columns</code> property indicates the number of columns in the grid, and the value of each parameter indicates the width of each column.</p>
    <p>To create rows, use the grid-template-rows property in exactly the same way as grid-template-columns was used:</p>
    <code class="code-block">grid-template-columns: 50px 50px 50px;</code>
    <p>This creates three rows, each 50px tall.</p>
    <p>You can set absolute and relative units like <code>px</code> and <code>em</code> in CSS Grid to define sizes of rows/columns. In addition, you can also use:</p>
    <ul>
      <li><code>fr:</code> sets the column or row to a fraction of the available space</li>
      <li><code>auto:</code>sets the column/row to the width or height of its content automatically</li>
      <li><code>%:</code> adjusts the column/row to the percent width of its container.</li>
    </ul>
  </section>
  <section class="main-section" id="Creating_Gaps">
    <header>Creating Gaps</header>
    <p>Sometimes you want a gap in between the columns. To add a gap between them, use the <code>grid-column-gap</code> property like this:</p>
    <pre><code class="code-block">display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
grid-column-gap: 20px;</code>
    </pre>
    <p>This creates a gap of 20px between all the columns.</p>
    <p>Just as with columns, you can add gaps between rows using <code>grid-row-gap</code>:</p>
    <pre><code class="code-block">display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
grid-column-gap: 20px;
grid-row-gap: 20px;</code></pre>
    <p>Now there is a 20px gap between all rows.</p>
    <p><code>grid-gap</code> is a short-hand property for <code>grid-row-gap</code> and <code>grid-column-gap</code> for convenience. If <code>grid-gap</code> has one value, it will create a gap between all rows and columns. However, if there are two values, it will use the first one to set the gap between rows, and the second value for columns.
      <ul>
        <li>First value = rows</li>
        <li>Second value = columns</li>
      </ul>
  </section>
  <section class="main-section" id="Area_Templates">
    <header>Area Templates</header>
    <p>You can group cells of your grid together into an area and give the area a custom name. Do this by using <code>grid-template-areas</code> on the container like this:</p>
    <pre><code class="code-block">grid-template-areas:
"header header header"
"advert content content"
"footer footer footer";</code></pre>
    <p>This code above merges the top three cells together into an area named header, the bottom three cells into a footer area, and it makes two areas in the middle row; advert and content.</p>
    <p>NOTE: every word in the code represents a cell, and every pair of quotation marks represents a row. In addition to custom labels, you can use a period (.) to designate an empty cell in the grid.</p>
  </section>
</main>
              
            
!

CSS

              
                body {
  margin: 0;
  display: flex;
  font-family: sans-serif;
  background-color: #e2f5dc;
  max-width: 100vw;
}

#navbar {
  display: flex;
  position: fixed;
  flex-direction: column;
  height: 100%;
  width: 20%;
  padding: 1em;
  border-right: 2px solid #1b2a33;
}

.nav-link {
  font-family: sans-serif;
  font-size: 1.2em;
  padding: 1em;
  text-align: left;
}

.main-section {
  margin-left: 25%;
  width: 70%;
}

section {
    padding-top: 5em;
    margin-top: -5em;
  }

header {
  font-size: 1.8em;
  font-weight: bold;
  padding-top: 1em;
  padding-bottom: 0.5em;
}

p {
  font-size: 1.2em;
}

ul {
  font-size: 1.2em;
}

code {
  font-size: 1.2em;
  font-weight: bold;
  color: #143d08;
}
.code-block {
  font-size: 1.5em;
  margin-left: 3%;
  padding: 0.5em;
  line-height: 1.5em;
  display: block;
  background-color: #1b2a33;
  color: #48c722;
}

@media only screen and (max-width: 768px) {
  #navbar {
    flex-direction: row;
    font-size: 0.8em;
    width: 100%;
    height: auto;
    padding: 0.5em;
    background-color: rgb(27, 42, 51);
    color: #48c722;
  }

  .nav-link {
    text-align: center;
    color: #fff;
  }

  main {
    margin-top: 6em;
  }
  
  .code-block {
    font-size: 1.1em;
}
}
              
            
!

JS

              
                // !! IMPORTANT README:

// You may add additional external JS and CSS as needed to complete the project, however the current external resource MUST remain in place for the tests to work. BABEL must also be left in place. 

/***********
INSTRUCTIONS:
  - Select the project you would 
    like to complete from the dropdown 
    menu.
  - Click the "RUN TESTS" button to
    run the tests against the blank 
    pen.
  - Click the "TESTS" button to see 
    the individual test cases. 
    (should all be failing at first)
  - Start coding! As you fulfill each
    test case, you will see them go   
    from red to green.
  - As you start to build out your 
    project, when tests are failing, 
    you should get helpful errors 
    along the way!
    ************/

// PLEASE NOTE: Adding global style rules using the * selector, or by adding rules to body {..} or html {..}, or to all elements within body or html, i.e. h1 {..}, has the potential to pollute the test suite's CSS. Try adding: * { color: red }, for a quick example!

// Once you have read the above messages, you can delete all comments. 

              
            
!
999px

Console