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

              
                <!-- A fixed square hamburger menu  -->

<!-- 
Description:
A combination of javascript and css to make a fixed menu that always appears over the content and in the same position of the screen no matter the size of the window.

Javascript is used to control the actions from the user such as mouse click and logic.

CSS is used purely for styling.

-->

<div id="main-menu-button" class="core-properties colour position">
  <span></span>
  <span></span>
  <span></span>
</div>

<div id="main-menu-container" class="main-menu-core-properties main-menu-position">

    <ul class="main-menu-items">
      <li>Menu item 1</li>
      <li>Menu item 2</li>
      <li>Menu item 3</li>
    </ul>

</div>

<div class="container">
  Div 1
</div>
<div class="container">
  Div 2
</div>

              
            
!

CSS

              
                .container {
  height:100vh;
  display:block;
  position:relative;
}

.position {
  position:fixed;
  top:30px;
  right:80px;
}

.core-properties {
  width:40px;
  height:40px;
  border:none;
  background:none;
}

.colour {
  color:black;
}
#main-menu-button {
  z-index:1;
}
#main-menu-button > span {
  display:block;
  position:relative;
  height:5px;
  width:30px;
  margin:5px 0;
  background-color:black;
}

.main-menu-core-properties {
  background-color:black;
  position:fixed;
  height:85vh;
  width:40vw;
  display:none;
}

.main-menu-show {
  display:block;
}

ul.main-menu-items {
  background-color:gray;
  width:80%;
  top:50%;
  position:absolute;
  left:50%;
  transform:translate(-50%,-50%);
  list-style:none;
  margin:0;
  padding:0;
}

ul.main-menu-items > li {
  text-align:center;
  margin:40px;
}

#main-menu-container.main-menu-position {
  top:50%;
  left:50%;
  transform:translate(-50%, -50%);
}
              
            
!

JS

              
                // Menu with vanilla javascript
function menuAction() {
  // console.info("Display Menu");
  var mainMenuContainer = document.querySelector("#main-menu-container");
    
  if (mainMenuContainer.classList.contains("main-menu-show")) {
    //if it contains the class main-menu-show, hide menu
    mainMenuContainer.classList.remove("main-menu-show");
  }
  else {
    //show the menu
    mainMenuContainer.classList.add("main-menu-show");
  }
  
}

var mainMenuButton = document.getElementById("main-menu-button");
console.warn(mainMenuButton);
mainMenuButton.addEventListener("click", menuAction);


              
            
!
999px

Console