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

              
                div#controls
  h1 Configuration

  div
    h4.control-header Position
    
    label.control-label
      input.control-input(
        name='position'
        onclick='setPosition("top")'
        type='radio'
        value='top'
      )
      span top
    label.control-label
      input.control-input(
        disabled
        name='position'
        onclick='setPosition("right")'
        type='radio'
        value='right'
      )
      span right
    label.control-label
      input.control-input(
        checked
        name='position'
        onclick='setPosition("bottom")'
        type='radio'
        value='bottom'
      )
      span bottom
    label.control-label
      input.control-input(
        disabled
        name='position'
        onclick='setPosition("left")'
        type='radio'
        value='left'
      )
      span left
      
  div
    h4.control-header Preview
    p.control-description The preview amount specifies how much of the hidden elements is shown when not hovered
    
    p Preview amount (in px)
    input.control-input(
      type='range'
      min=5
      max=20
      value=10
      onchange='setPreview(this.value)'
    )
      
  div
    h4.control-header Spacing
    
    p From parent (in px)
    input.control-input(
      type='range'
      min=0
      max=16
      value=10
      onchange='setSpaceFromParent(this.value)'
    )
    
    p Space between (in px)
    input.control-input(
      type='range'
      min=8
      max=24
      value=10
      onchange='setSpaceBetween(this.value)'
    )
    
  div
    h4.control-header Side buffers
    p.control-description The side buffer makes sure the menu isn&apos;t hidden immediately when the cursor goes beyond the sides
    
    p Side amount (in px)
    input.control-input(
      type='range'
      min=0
      max=20
      value=10
      onchange='setSideBuffer(this.value)'
    )

    p End amount (in px) 
    input.control-input(
      type='range'
      min=0
      max=20
      value=10
      onchange='setEndBuffer(this.value)'
    )

    label.control-label
      input.control-input(
        type='checkbox'
        onclick='toggleShowBuffer()'
      )
      span show buffers
  
  div
    h4.control-header Miscellaneous
    label.control-label
      input.control-input(
        type='checkbox'
        onclick='toggleConstantHover()'
      )
      span toggle hover

    label.control-label
      input.control-input(
        type='checkbox'
        onclick='toggleTransparent()'
      )
      span transparent

    label.control-label
      input.control-input(
        type='checkbox'
        onclick='toggleWireframe()'
      )
      span wireframe
  
  div
    h4.control-header Items
    button(
      id="add-item"
      class="control-button"
      onclick='addItem()'
    ) Add item
    button(
      id="remove-item"
      class="control-button"
      onclick='removeItem()'
    ) Remove item

div#preview
  div.menu
    div.primary.list-item
      h1 Hello there &#x1F44B;
      p
        | Hover over this element and the menu will appear 
        i #nojavascript

    div.list
      //- noscript.secondary
      //-   p This message only shows if you disable JavaScript

      div.list-item
        p This is a hidden message

      div.list-item
        p This is another message
        
      div.list-item.list-item--image
        img(src="https://source.unsplash.com/5qKY5d7j-cc" alt="some image")
        
      div.list-item
        p The message has
        p multiple lines!

              
            
!

CSS

              
                /* component */
.menu {
  position: absolute;
  width: 400px;
  
  top: 40px;
  left: 50%;
  transform: translate(-50%, 0);
}
.menu > .list-item {
  box-shadow: 0 0 4px 0 var(--shadow-color);
  padding: 24px 32px 24px;
  transition: box-shadow .2s ease;
  z-index: 2;
}
.list-item {
  background-color: white;
  box-sizing: border-box;
  margin: 0;
  position: relative;
  width: 100%;
}
.list {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  margin: 0;
  max-height: calc(100% + var(--preview-px));
  min-height: calc(100% + var(--preview-px));
  overflow: hidden;
  padding: 0;
  padding-bottom: 0;
  position: absolute;
  pointer-events: none;
  top: 0;
  transition:
    min-height 0s .4s ease-in,
    max-height .4s cubic-bezier(0, 1, 1, 1),
    
    /* */
    padding .3s ease-out,
    
    /* Slowly move the entire box to the top, wait a bit for transform of list items */
    bottom .4s .1s ease-out,
    top .4s .1s ease-out;
  width: 100%;
  z-index: 1;
}
.list > .list-item {
  flex-shrink: 0;
  margin: -40px 0 0 0;
  overflow: hidden;
  padding: 0 32px;
  position: relative;
  transform: scale(.95);
  transition:
    /* Hide box-shadow when no longer visibile */
    box-shadow 0s .3s ease,
    
    /* wait with transform until scaled down */
    margin .3s .1s ease-out,
    
    /* transition for scaling */
    transform .2s ease-out;
  z-index: 1;
}
.menu:not(:hover) .list-item:last-child {
  box-shadow: 0 0 var(--shadow-size-list) 0 var(--shadow-color);
  z-index: 2;
}

/* component: top */
.menu--top {
  bottom: 40px;
  
  /* reset defaults */
  top: auto;
}
.menu--top .list {
  bottom: 0;
  flex-direction: column-reverse;
  
  /* reset defaults */
  top: auto;
}
.menu--top .list > .list-item {
  margin: 0 0 -40px 0;
}

/* component: hovered */
.list-item:hover {
  box-shadow: 0 0 6px 0 rgba(0, 0, 0, .4) !important;
}
.hovered .list,
.menu:hover .list {
  height: auto;
  max-height: 9999px;
  min-height: 0;
  padding: var(--shadow-size-list);
  padding-top: var(--space-from-parent);
  pointer-events: all; 
  top: 100%;
  transition:
    bottom .25s ease,
    top .25s ease;
}
.hovered .list > .list-item,
.menu:hover .list > .list-item {
  box-shadow: 0 0 var(--shadow-size-list) 0 var(--shadow-color);
  margin: var(--space-between) 0 0;
  padding: 1px 32px;
  transform: scale(1);
  transition:
    /* Normal box-shadow transition */
    box-shadow .2s ease,
    
    /* margin time < transform delay */
    margin .25s ease-out,
    
    /* wait with transform until .secondaires top transition */
    transform .2s .25s ease-out;
}

/* component: hovered, top */
.hovered .menu--top .menu--top .list,
.menu--top:hover .list {
  bottom: 100%;
  padding-bottom: var(--space-from-parent);
  
  /* reset defaults */
  padding-top: var(--shadow-size-list);
  top: auto;
}
.hovered .menu--top .list > .list-item,
.menu--top:hover .list > .list-item {
  margin: 0 0 var(--space-between);
}

/* component: item modifiers */
.list-item--image {
  font-size: 0;
  padding: 0 !important;
}
.list-item--image img {
  height: auto;
  margin: 0;
  width: 100%;
}

/* page layout */
html,
body {
  box-sizing: border-box;
  height: 100%;
  margin: 0;
  overflow: hidden;
  padding: 0;
  width: 100%;
}
body {
  display: grid;
  grid-template-columns: 30% 70%;
  grid-template-rows: 100%;
}

#controls {
  box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.4);
  box-sizing: border-box;
  font-family: monospace;
  grid-column: 1 / 2;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 18px 28px;
  z-index: 2;
}
.control-header {
  font-size: 1.25em;
  margin: 1.25em 0 .3em;
}
.control-description {
  font-style: italic;
}
.control-label {
  display: block;
}
.control-input[type="checkbox"],
.control-input[type="radio"] {
  margin: 0 8px 0 0;
}

#preview {
  background-color: #fafafa;
  box-sizing: border-box;
  font-family: sans-serif;
  grid-column: 2 / 3;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
  z-index: 1;
}

/* wireframe */
.wireframe .list-item {
  background-color: transparent;
  border: 1px solid black;
  box-shadow: none !important;
  color: transparent;
}
.wireframe img {
  opacity: 0;
}

/* default config */
:root {
  /* static */
  --shadow-color: rgba(0, 0, 0, .25);
  --shadow-size-list: 4px;
  
  /* configurable */
  --side-buffer: 10px;
  --side-buffer-color: transparent;
  --end-buffer: 10px;
  --end-buffer-color: transparent;
  --opacity: 1;
  --preview-px: 8px;
  --space-between: 10px;
  --space-from-parent: 0px;
}

.menu > .list-item {
  opacity: var(--opacity);
}
.hovered .list,
.menu:hover .list {
  /* Side buffer preview */
  border-left: var(--side-buffer);
  border-left-color: var(--side-buffer-color);
  border-left-style: solid;
  border-right: var(--side-buffer);
  border-right-color: var(--side-buffer-color);
  border-right-style: solid;
  margin-left: calc(-1 * (var(--shadow-size-list) + var(--side-buffer)));
}
.menu:not(.menu--top) .list {
  border-bottom: var(--end-buffer);
  border-bottom-color: var(--end-buffer-color);
  border-bottom-style: solid;
  padding-bottom: var(--shadow-size-list);
}
.menu--top .list {
  border-top: var(--end-buffer);
  border-top-color: var(--end-buffer-color);
  border-top-style: solid;
  padding-top: var(--shadow-size-list);
}

              
            
!

JS

              
                var $preview = document.getElementById("preview");
var $container = $preview.querySelector(".menu");
var $items = $preview.querySelector(".list");
var $removeItemButton = document.getElementById("remove-item")

/* Colors */

var clrSideBuffer = "salmon";
var clrEndBuffer  = "pink";

/* Controls */

function setPosition(position) {
  $container.classList.remove(
    'menu--top',
    'menu--right',
    'menu--left'
  );
  
  switch(position) {
    case 'top':
      $container.classList.add('menu--top');
      break;
    case 'right':
      $container.classList.add('menu--right');
      break;
    case 'bottom':
      // Default position is bottom
      break;
    case 'left':
      $container.classList.add('menu--left');
      break;
  }
}

function setSpaceBetween(amount) {
  $preview.style.setProperty("--space-between", amount + "px");
}

function setSpaceFromParent(amount) {
  $preview.style.setProperty("--space-from-parent", amount + "px");
}

function setPreview(amount) {
  $preview.style.setProperty("--preview-px", amount + "px");
}

var showBuffers = false;
function toggleShowBuffer() {
  showBuffers = !showBuffers;
  
  var $preview = document.getElementById("preview");
  $preview.style.setProperty("--side-buffer-color", showBuffers ? clrSideBuffer : "transparent");
  $preview.style.setProperty("--end-buffer-color", showBuffers ? clrEndBuffer : "transparent");
}

function setSideBuffer(amount) {
  $preview.style.setProperty("--side-buffer", amount + "px");
}

function setEndBuffer(amount) {
  $preview.style.setProperty("--end-buffer", amount + "px");
}

var constantHover = false;
function toggleConstantHover() {
  $preview.classList.toggle("hovered");
}

var transparent = false;
function toggleTransparent() {
  transparent = !transparent;
  $preview.style.setProperty("--opacity", transparent ? ".4" : "1");
}

function toggleWireframe() {
  $preview.classList.toggle("wireframe");
}

/* Items */
function addItem() {
  var item = document.createElement("div");
  item.classList.add('list-item');
  
  var child;
  if (Math.random() > .314) {
    child = document.createElement("p");
    child.innerHTML = getRandomText();
  } else {
    item.classList.add("list-item--image");
    child = document.createElement("img");
    child.src = getRandomImage();
  }
  item.appendChild(child);
  
  $items.appendChild(item);
  
  $removeItemButton.disabled = false;
}
function removeItem() {
  $items.removeChild($items.lastElementChild);
  if ($items.lastElementChild === null) {
    $removeItemButton.disabled = true;
  }
}

/* Values */

function getRandomText() {
  var i = Math.floor(Math.random() * textSamples.length);
  return textSamples[i];
}
var textSamples = [
  "If you see a rat the size of a car, you're playing the wrong game",
  "These are not the droids you're looking for",
  "",
  "Double rainbow, what does it mean?",
  "As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed in his bed into a gigantic insect.",
  "Is mayonnaise an instrument?",
  "The children thought lions, and there were lions. The children thought zebras, and there were zebras. Sun – sun. Giraffes – giraffes. Death and death.",
  "Gibbs walked over to the freshly ignited fire and said, \"Why don't we use the ship chemical fire instead  of that wood?\"<br>\"Never mind,\" said Spender, not looking up.",
  "I wrote out the semagrams for \"process create-endpoint inclusive-we,\" meaning \"let's start.\" Raspberry replied in the affirmative, and the slide shows began",
  "Finally Samuel Teece held his empty shoe up in triumph, turned it over, stared at it, and said, \"Did you notice? Right up to the very last, by God, he said 'Mister'!",
  "\"Practical wisdom,\" Aristotle told us, \"is the combination of moral will and moral skill.\""
];

function getRandomImage() {
  var i = Math.floor(Math.random() * images.length);
  return images[i];
}
var images = [
  "https://source.unsplash.com/krY-4Yjqo8c",
  "https://source.unsplash.com/EOebHxC4DaA",
  "https://source.unsplash.com/ZDwp-QdzoH8",
  "https://source.unsplash.com/F3rDBnQQbQU",
  "https://source.unsplash.com/Xvlc79bu9MA",
  "https://source.unsplash.com/vgy7iw7rGg8",
  "https://source.unsplash.com/vNMA0U8yxio",
  "https://source.unsplash.com/9NUeLk0uqME",
  "https://source.unsplash.com/XLICu2pG_9U",
  "https://source.unsplash.com/8lweosfn6Gk",
  "https://source.unsplash.com/wUu3lziuZLw",
  "https://source.unsplash.com/R261qkc-nDE"
];

              
            
!
999px

Console