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

              
                <!-- Top Navigation Bar -->
<div class="topnav">
  <a href="#">Home</a>
  <a href="#" class="active">News</a>
  <a href="#">Contact</a>
  <a href="#">About</a>
</div>

<!-- Side Navigation Bar -->
<div class="sdnav">
  <a href="#">What</a>
  <a href="#" class="active">Where</a>
  <a href="#">When</a>
  <a href="#">How</a>
</div>

<div class="main">
  <h1>
    Responsive Top and Side Navigation Bars - using <span style="color: red;">flexbox</span>
  </h1>

  <p>
    This example uses a Mobile-First Design.
  </p>

  <p>
    It uses the following media queries:
  </p>

  <ol>
    <li>
      The first stacks the TopNav <em>horizontally</em> when the screen size is <strong>600px</strong> or more.
    </li>

    <li>
      The first stacks the SideNav <em>horizontally</em>, when the screen size is <strong>600px</strong> or more.
    </li>

    <li>
      The third stacks the SideNav <em>vertically</em>, at the left, when the screen size is <strong>768px</strong> or more.
    </li>
  </ol>

  <h4>Resize the browser window to see the effect.</h4>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  margin: 0;
}

/* Extra small devices (phones) */

/* Top navigation bar -
         Stack the options vertically at the center,
         when the screen width is below 600px. */
.topnav {
  display: flex;
  flex-direction: column; /* vertical stack */

  background-color: #777; /* gray */
}

/* Top Navigation bar links */
.topnav a {
  padding: 14px 20px;
  color: white;
  text-decoration: none;
  text-align: center;
}

/* Change link color on hover */
.topnav a:hover:not(.active) {
  background-color: #bbb; /* light gray */
  color: black;
}

.topnav a.active {
  background-color: #4caf50; /* green */
}

/* Side navigation bar -
         Stack the options vertically at the center,
         when the screen width is below 600px. */
.sdnav {
  display: flex;
  flex-direction: column;

  width: 100%;
  height: auto;
  position: relative;
  background-color: #f1f1f1; /* light gray */
}

/* Side navigation bar links */
.sdnav a {
  padding: 14px 20px;
  color: black;
  text-decoration: none;
  text-align: center;
}

/* Change link color on hover */
.sdnav a:hover:not(.active) {
  background-color: #888; /* light gray */
  color: white;
}

.sdnav a.active {
  background-color: lightgreen;
  color: white;
}

.main {
  padding: 10px;
}

/* Small devices 
         (portrait tablets and large phones, 
          600px and up) */
@media screen and (min-width: 600px) {
  .topnav {
    flex-direction: row; /* horizontal stack */
  }
}

/* Stack the sdnav horizontally when the screen width 
         is 600px or more. */
@media screen and (min-width: 600px) {
  .sdnav {
    flex-direction: row;
  }

  .sdnav a {
    text-align: center;
  }
}

/* Stack the sdnav vertically when the screen width 
         is 768px or more. */
@media screen and (min-width: 768px) {
  .sdnav {
    flex-direction: column;

    width: 200px;
    height: 100%;
    position: fixed;
    overflow: auto;
  }

  .sdnav a {
    width: auto;
    text-align: left;
  }

  .main {
    margin-left: 200px;
    height: 1000px;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console