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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <h1>
  Shortcut Menu Helper
</h1>

<form class="form">
  <input type="text" class="input" value="Focus this input" placeholder="Focus this input"/>
  <div class="shortcut-helper-menu hidden">
    <h1 class="header">Keyboard Shortcuts</h1>
    <div class="shortcut">
      <div class="label">Play/Pause</div>
      <div class="key-command">
        <span class="key key-16">Shift</span> + <span class="key key-32">Space</span>
      </div>
    </div>
    <div class="shortcut">
      <div class="label">Skip Forward</div>
      <div class="key-command">
        <span class="key key-16">Shift</span> + <span class="key key-39">Right Arrow</span>
      </div>
    </div>
    <div class="shortcut">
      <div class="label">Skip Backwards</div>
      <div class="key-command">
        <span class="key key-16">Shift</span> + <span class="key key-37">Left Arrow</span>
      </div>
    </div>
  </div>
</form>


              
            
!

CSS

              
                $color-bg:#1f242a;
$color-highlight: #00c7b2;
$color-menu-bg: #eee;

body{
  font: 16px/1.4 'Proxima Nova', sans-serif;
  letter-spacing:.05em;
  background:$color-bg;
  color: #1f242a;
}

.form{
  width:200px;
  margin:auto;
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
  
  .input{
    display:block;
    line-height:2rem;
    text-align:center;
    width:100%;
  }
}

.shortcut-helper-menu{
  position:absolute;
  bottom:100%;
  left:0;
  padding:1rem;
  background:#eee;
  opacity:.9;
  margin-bottom:1rem;
  border-radius:4px;

  &:after{
    content:'';
    display:block;
    width:0;
    border-style:solid;
    border-width: 10px 10px 0;
    border-color: $color-menu-bg transparent transparent;
    position:absolute;top:100%;
    left:10px;
  }
  
  &.hidden{
    display:none;
  }
  &.shown{
    display:block;
  }
}

.header{
  font-weight:600;
  margin-bottom:1rem;
}

.shortcut{
  display:flex;
  align-items:center;
  margin-bottom:1rem;
  white-space:nowrap;
}

.label{
  margin-right:1rem;
  width:8rem;
}

.key{
  display:inline-block;
  background:#ddd;
  line-height:1.6rem;
  padding:0 .5rem;
  border-radius:4px;
  &.pressed{
    background:$color-highlight;
  }
}
              
            
!

JS

              
                var input = document.querySelector('.input');
var helperMenu = document.querySelector('.shortcut-helper-menu');

function addHighlight(keyCode){
  $('.key-' + keyCode).addClass('pressed');
}

function removeHighlight(keyCode){
  $('.key-' + keyCode).removeClass('pressed');
}

window.addEventListener('keydown', function(event){
  if(event.shiftKey){
    event.preventDefault();
  }
  addHighlight(event.keyCode);
});

window.addEventListener('keyup', function(event){
  removeHighlight(event.keyCode);
});

input.addEventListener('focus', function(){
  $(helperMenu).toggleClass('hidden', 'shown');
})

input.addEventListener('blur', function(){
  $(helperMenu).toggleClass('hidden', 'shown');
})


              
            
!
999px

Console