Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                /// 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;
}
@import url("https://fonts.googleapis.com/css?family=Roboto|Roboto+Mono&display=swap");

:root {
  --background-color: hsl(228, 8%, 12%);
  --text-color: hsl(0, 0%, 85%);
  --border-color: hsl(228, 8%, 20%);
  --transparency-bg: url(data:image/gif;base64,R0lGODlhDAAMAHAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQICgAAACwAAAAADAAMAIDX19f///8CFoQfqYeabNyDMkBQb81Uat85nxguUAEAOw==);
  --border-radius: .3rem;
  --regular-font: Roboto, sans-serif;
  --monospace-font: 'Roboto Mono', monospace;
  --form-field-bg: hsl(0, 0%, 95%);
  --form-field-color: hsl(228, 8%, 12%);
  --link-color: hsl(206, 89%, 45%);
}

html {
  font-size: 62.5%;
  box-sizing: border-box;
}

a {
  color: var(--link-color);
}

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

body {
  font: 1.4rem/1.5 var(--regular-font);
  background: var(--background-color);
  color: var(--text-color);
  margin: 0;
}

h1 {
  font-size: 2.4rem;
}

input, textarea, pre, select, [data-preview] {
  background: var(--form-field-bg);
  color: var(--form-field-color);
}

code, input, textarea, pre, select, [data-preview] {
  font-family: var(--monospace-font);  
}

input, textarea, pre, select, fieldset, [data-preview] {
  border: .1rem var(--border-color) solid;
}

pre {
  color: hsl(0, 0%, 15%);
  background: hsl(0, 0%, 85%);
  padding: 1rem;
  max-height: calc(100vh - 40px);
  overflow: auto;
}

              
            
!

JS

              
                
              
            
!
999px

Console