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

              
                <main>   
  <section>
    <h2>1. Borders on <code>::before</code> and <code>::after</code></h2>
    <p>This is the classic approach with three transparent and one colored border. It has the disadvantage that the clickable zone of a link is still a rectangle. Go for instance to the top left corner of the second link. You will notice that you are actually already on the third link.</p>
    <ul class="border-as-triangle">
      <li>
        <a href="#1">Link</a>
      </li>
      <li>
        <a href="#2">Link</a>
      </li>
      <li class="active">
        <span class="a">Active</span>
      </li>
      <li>
        <a href="#4">Link</a>
      </li>
      <li>
        <span class="a">No link</span>
      </li>
    </ul>
  </section>
  
  <section>
    <h2>2. Skewing and rotating <code>::after</code></h2>
    <p>With this approach the clickable zone is identical to the visual representation of a link - you move outside of the triangle and are on the next link.</p>
    <ul class="after-as-rhombus">
      <li>
        <a href="#1">Link</a>
      </li>
      <li>
        <a href="#2">Link</a>
      </li>
      <li class="active">
        <span class="a">Active</span>
      </li>
      <li>
        <a href="#4">Link</a>
      </li>
      <li>
        <span class="a">No link</span>
      </li>
    </ul>
  </section>
  <section>
    <h2>3. Cutting off with <code>clip-path: polygon()</code></h2>
  <p>A third way to achieve this is to use <code>clip-path: polygon()</code>. Browser support meanwhile is <a href="https://caniuse.com/#search=clip-path" target="_blank">OK-ish</a>.</p>
    <ul class="clip-path-polygon">
      <li>
        <a href="#1">Link</a>
      </li>
      <li>
        <a href="#2">Link</a>
      </li>
      <li class="active">
        <span class="a">Active</span>
      </li>
      <li>
        <a href="#4">Link</a>
      </li>
      <li>
        <span class="a">No link</span>
      </li>
    </ul>
  </section>
</main>


              
            
!

CSS

              
                // Note: The demo also uses `normalize.css`
// and https://codepen.io/draber/pen/BayEGwb

/// colors
$col-1: #336;
$col-2: #babae7;
$col-3: #003;

/// navi elements
ul {
  padding: 0 50px 0 0;
  list-style: none;
  overflow: hidden;
  display: flex;
  font-size: 1.3rem;
}

li {
  display: block;
  white-space: nowrap;
  &:first-of-type {
    a,
    .a {
      padding-left: 35px;
      border-left: 1px solid $col-1;
    }
  }
  &.active {
    a,
    .a {
      background: $col-3;
      color: $col-2;
    }
  }
  .a {
    cursor: default;
  }
}

ul {
  a,
  .a {
    border-top: 1px solid $col-1;
    border-bottom: 1px solid $col-1;
    padding: 0 15px 0 60px;
    display: inline-block;
    position: relative;
    line-height: 80px;
    text-decoration: none;
    color: $col-1;
    background: $col-2;
  }
  a {
    &:hover {
      color: $col-2;
      background: $col-1;
    }
  }
}

/// border as a triangle technique
.border-as-triangle {
  li {
    &.active {
      a,
      .a {
        &::before {
          border-left-color: $col-3;
        }
        &::after {
          border-left-color: $col-2;
        }
        &:hover {
          &::before {
            border-left-color: $col-3;
          }
        }
      }
    }
    a {
      &:hover {
        &::before {
          border-left-color: $col-1;
        }
        &::after {
          border-left-color: $col-2;
        }
      }
    }
    a,
    .a {
      &::before,
      &::after {
        content: "";
        display: block;
        width: 0;
        height: 0;
        border-top: 41px solid transparent;
        border-bottom: 41px solid transparent;
        position: absolute;
        top: 50%;
        margin-top: -41px;
        left: 100%;
      }
      &::before {
        border-left: 30px solid $col-2;
        z-index: 2;
      }
      &::after {
        border-left: 30px solid $col-1;
        margin-left: 1px;
        z-index: 1;
      }
    }
  }
}

// Transform to rhombus approach
.after-as-rhombus {
  li {
    &.active {
      a,
      .a {
        &::after {
          border-color: $col-2;
        }
      }
    }

    /// link stacking order from highest to lowest
    $countLinks: 4;
    $highest: $countLinks;
    @for $i from 1 through $countLinks {
      &:nth-of-type(#{$i}) {
        z-index: $highest;
      }
      $highest: $highest - 1;
    }
  }
  a {
    &:hover {
      &::after {
        border-color: $col-2;
      }
    }
  }
  a,
  .a {
    &::after {
      content: "";
      display: block;
      height: 95px;
      width: 95px;
      transform: rotate(45deg) skew(10deg, 10deg);
      position: absolute;
      top: -7px;
      z-index: -1;
      right: -21px;
      z-index: -1;
      background: inherit;
      border: 1px $col-1 solid;
    }
  }
}

//  Cutting off with clip-path: polygon()
.clip-path-polygon {
  li {
    &.active {
      a,
      .a {
        &::after {
          background: $col-2;
        }
      }
    }

    /// link stacking order from highest to lowest
    $countLinks: 4;
    $highest: $countLinks;
    @for $i from 1 through $countLinks {
      &:nth-of-type(#{$i}) {
        z-index: $highest;
      }
      $highest: $highest - 1;
    }
  }
  a {
    &:hover {
      &::after {
        background: $col-2;
      }
    }
  }
  a,
  .a {
    &::before,
    &::after {
      content: "";
      display: block;
      height: calc(100% + 2px); // + 2 for parent borders
      width: 120px;
      position: absolute;
      top: -1px;
      right: -120px;
      clip-path: polygon(0 0, 0% 100%, 30px 50%);
    }
    &::before {
      right: -119px;
      background: inherit;
      z-index: 1;
    }
    &::after {
      right: -120px;
      background: $col-1;
    }
  }
}

/// some basic setup
html {
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  padding: 0 2rem;
  font: 14px sans-serif;
}

main {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

section {
  width: 48%;
}

p {
  min-height: 35px;
}

              
            
!

JS

              
                
              
            
!
999px

Console