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

              
                <h1>Handling the diagonal submenu problem in CSS (without JavaScript)</h1>
<h2>Illustration of the problem</h2>
<p>Try to mouse over the Second navigation item and then try to reach the text in the sub navigation in a straight line, crossing the area of First navigation, thus accidentally activating the sub of First.</p>
<ul class="nav">
  <li class="nav-item bg-1">
    <a href="#" class="nav-link">First
      <div class="after"></div>
    </a>
    <div class="sub-nav bg-1">
      First sub
    </div>
  </li>
  <li class="nav-item bg-2">
    <a href="#" class="nav-link">Second</a>
    <div class="sub-nav bg-2">
      Second sub
    </div>
  </li>
  <li class="nav-item bg-3">
    <a href="#" class="nav-link">Third</a>
    <div class="sub-nav bg-3">
      Third sub
    </div>
  </li>
</ul>

<h2>The solution with hover help areas visible</h2>
<ul class="nav">
  <li class="nav-item bg-1">
    <a href="#" class="nav-link hover-help hover-help-visible">First
      <div class="after"></div>
    </a>
    <div class="sub-nav bg-1">
      First sub
    </div>
  </li>
  <li class="nav-item bg-2">
    <a href="#" class="nav-link hover-help hover-help-visible">Second</a>
    <div class="sub-nav bg-2">
      Second sub
    </div>
  </li>
  <li class="nav-item bg-3">
    <a href="#" class="nav-link hover-help hover-help-visible">Third</a>
    <div class="sub-nav bg-3">
      Third sub
    </div>
  </li>
</ul>

<h2>The solution - with invisible hover help</h2>
<ul class="nav">
  <li class="nav-item bg-1">
    <a href="#" class="nav-link hover-help">First
      <div class="after"></div>
    </a>
    <div class="sub-nav bg-1">
      First sub
    </div>
  </li>
  <li class="nav-item bg-2">
    <a href="#" class="nav-link hover-help">Second</a>
    <div class="sub-nav bg-2">
      Second sub
    </div>
  </li>
  <li class="nav-item bg-3">
    <a href="#" class="nav-link hover-help">Third</a>
    <div class="sub-nav bg-3">
      Third sub
    </div>
  </li>
</ul>
              
            
!

CSS

              
                * {
  font-family: sans-serif;
  box-sizing: border-box;
}
body {
  padding: 1rem;
}

.nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  position: relative;
  background-color: dodgerblue;
  margin-bottom: 16rem;
}
.nav-link {
  display: block;
  flex: 1;
  position: relative;
  padding: 2rem 4.5rem;
  color: white;
  text-decoration: none;
  border-right: 1px solid white;
}
@keyframes subnavHoverHelp {
    0% {
      width: 100%;
    }
    99% {
      width: 100%;
    }
    100% {
      width: 0;
    }
}

.hover-help:hover::before,
.hover-help:hover::after {
  content: "";
  position: absolute;
  z-index: 1000;
  bottom: 0;
  height: 80%;
  animation: subnavHoverHelp 1.2s;
}
.hover-help-visible:hover::before,
.hover-help-visible:hover::after {
  background-color: fuchsia;
  opacity: .3;
}
.hover-help:hover::before {
  left: -100%;
  clip-path: polygon(100% 0, 0% 100%, 100% 100%);
}
.hover-help:hover::after {
  right: -100%;
  clip-path: polygon(0 0, 0% 100%, 100% 100%);
}

.nav-item:hover .sub-nav {
  display: block;
}

.sub-nav {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  padding: 2rem;
  width: 100%;
  height: 14rem;
  color: white;
}

.bg-1 {
  background-color: darkmagenta;  
}
.bg-2 {
  background-color: navy; 
}
.bg-3 {
  background-color: darkgreen;    
}
              
            
!

JS

              
                
              
            
!
999px

Console