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

              
                <ul id="wrapper">
  <li id="minimize"><svg width="11" height="1" viewBox="0 0 11 1">
      <path d="m11 0v1h-11v-1z" stroke-width=".26208" />
    </svg>
  </li>
  <li id="maximize"><svg width="10" height="10" viewBox="0 0 10 10">
      <path d="m10-1.6667e-6v10h-10v-10zm-1.001 1.001h-7.998v7.998h7.998z" stroke-width=".25" />
    </svg>
  </li>
  <li id="close"><svg width="12" height="12" viewBox="0 0 12 12">
      <path d="m6.8496 6 5.1504 5.1504-0.84961 0.84961-5.1504-5.1504-5.1504 5.1504-0.84961-0.84961 5.1504-5.1504-5.1504-5.1504 0.84961-0.84961 5.1504 5.1504 5.1504-5.1504 0.84961 0.84961z" stroke-width=".3" />
    </svg></li>
  <div id="highlight"></div>
</ul>
              
            
!

CSS

              
                body {
  display: flex;
  justify-content: center;
}

ul {
  position: relative;
  list-style: none;
  display: flex;
  white-space: nowrap;
  padding: 0;
}

li {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  vertical-align: middle;
  padding: 0.8rem 1.2rem;
  cursor: pointer;
  border-radius: 5px;
}

#highlight {
  /* initially only opacity is animated: */
  transition-property: opacity;
  transition-duration: 200ms;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  z-index: -10;
  position: absolute;
  min-height: 100%;
  border-radius: 5px;
  background-color: #bbbbbb;
  opacity: 0;
}

/* animation of property "left" is switched on
            when the class "transition-active" is set: */
#highlight.transition-active {
  transition-property: all;
}

#wrapper svg {
  transition-duration: 200ms;
}

#close:hover svg {
  fill: white;
}

#close:hover + #highlight {
  background-color: #e31219;
}

              
            
!

JS

              
                const defaultSelection = document.getElementById("minimize");
const highlight = document.getElementById("highlight");
const wrapper = document.getElementById("wrapper");

let timer;

wrapper.addEventListener("mouseleave", (event) => {
  highlight.style.opacity = 0;
  // we remove the class "transition-active"
  // so that shifting the highlight
  // is done immediately without animation
  // when the mouse is entering again:
  timer = setTimeout(() => {
    highlight.classList.remove("transition-active");
  }, 200)
});

document.querySelectorAll("li").forEach((item) => {
  item.addEventListener("mouseover", (event) => {
    timer && clearTimeout(timer);
    // after page load or when the mouse is entering
    // the wrapper, transition is switched of,
    // therefore shifting the highlight is done without transition
    setStyles(highlight, event.target.closest("li"));
    highlight.style.opacity = 1;
    // subsequently shifting the highlight should be animated,
    // therefore switch on transition
    // after waiting for a short moment:
    setTimeout(() => {
      highlight.classList.add("transition-active");
    }, 0);
  });
});

function setStyles(elementToStyle, eventTarget) {
  elementToStyle.style.width = getStyles(eventTarget).w + "px";
  elementToStyle.style.height = getStyles(eventTarget).h + "px";
  elementToStyle.style.left = getStyles(eventTarget).pos + "px";
}

function getStyles(target) {
  return {
    w: target.scrollWidth,
    h: target.scrollHeight,
    pos: target.offsetLeft
  };
}

              
            
!
999px

Console