Breadcrumb Nav with Counter

By Rafi

F6
#
How do I use This?

A nifty breadcrumb navigation using CSS counters to automatically number each step.

HTML
<ul class="breadcrumb-counter-nav">
  <li class="breadcrumb-counter-nav-item"><a href="#">Setup</a></li>
  <li class="breadcrumb-counter-nav-item current"><a href="#">Sample Analysis</a></li>
  <li class="breadcrumb-counter-nav-item"><a href="#">Sort Layout</a></li>
  <li class="breadcrumb-counter-nav-item"><a href="#">Sort</a></li>
  <li class="breadcrumb-counter-nav-item"><a href="#">Reporting</a></li>
</ul>

$font-color: #fff;
$nav-background: #2C3E50;


body {
  counter-reset: section;
}

.breadcrumb-counter-nav {
  margin: 0;
  padding: 0;
  display: flex;
  width: 100%;
  list-style: none;
  background: $nav-background;

  .breadcrumb-counter-nav-item {
    position: relative;
    flex: 1 0 auto;
    padding: 1rem 2rem;
    text-align: center;
    vertical-align: middle;
    cursor: pointer;

    &:hover {
      background: darken($nav-background, 10%);
    }

    &::before {
      counter-increment: section;
      content: counter(section);
      position: relative;
      background: lighten($nav-background, 20%);
      color: $font-color;
      right: 0.8rem;
      border-radius: 50%;
      padding:  0.2em 0.55em;
    }

    &.current {
      background: darken($nav-background, 10%);

      &::after {
        content: '';
        position: absolute;
        top: 0;
        right: -1rem;
        width: 0;
        height: 0;
        border-top: 1.75rem solid transparent;
        border-bottom: 1.75rem solid transparent;
        border-left: 1rem solid darken($nav-background, 10%);
        z-index: 300;
      }

      &::before {
        background-color: lighten(#22313F, 45%);
      }
    }

    a {
      color: $font-color;
      font-size: 0.875rem;
    }
  }

  @media only screen and (max-width: 52em) {
    flex-direction: column;
  }
}


body {
  counter-reset: section;
}

.breadcrumb-counter-nav {
  margin: 0;
  padding: 0;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  width: 100%;
  list-style: none;
  background: #2C3E50;
}

.breadcrumb-counter-nav .breadcrumb-counter-nav-item {
  position: relative;
  -webkit-flex: 1 0 auto;
      -ms-flex: 1 0 auto;
          flex: 1 0 auto;
  padding: 1rem 2rem;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
}

.breadcrumb-counter-nav .breadcrumb-counter-nav-item:hover {
  background: #1a252f;
}

.breadcrumb-counter-nav .breadcrumb-counter-nav-item::before {
  counter-increment: section;
  content: counter(section);
  position: relative;
  background: #507192;
  color: #fff;
  right: 0.8rem;
  border-radius: 50%;
  padding: 0.2em 0.55em;
}

.breadcrumb-counter-nav .breadcrumb-counter-nav-item.current {
  background: #1a252f;
}

.breadcrumb-counter-nav .breadcrumb-counter-nav-item.current::after {
  content: '';
  position: absolute;
  top: 0;
  right: -1rem;
  width: 0;
  height: 0;
  border-top: 1.75rem solid transparent;
  border-bottom: 1.75rem solid transparent;
  border-left: 1rem solid #1a252f;
  z-index: 300;
}

.breadcrumb-counter-nav .breadcrumb-counter-nav-item.current::before {
  background-color: #88a4bf;
}

.breadcrumb-counter-nav .breadcrumb-counter-nav-item a {
  color: #fff;
  font-size: 0.875rem;
}

@media only screen and (max-width: 52em) {
  .breadcrumb-counter-nav {
    -webkit-flex-direction: column;
        -ms-flex-direction: column;
            flex-direction: column;
  }
}

JS
$('.breadcrumb-counter-nav-item').click(function () {
  $('.breadcrumb-counter-nav-item').removeClass('current');
  $(this).addClass('current');
});