Let us know what you think about the new Building Blocks

Hover Underline Menu

By Val Ery

F6
#
How do I use This?

Underline menu items

HTML
<nav class="hover-underline-menu" data-menu-underline-from-center>
  <ul class="menu align-center">
    <li><a href="#">One</a></li>
    <li><a href="#">Two</a></li>
    <li><a href="#">Three</a></li>
    <li><a href="#">Four</a></li>
  </ul>
</nav>

$menu-underline-from-center-bg: #2C3840;
$menu-underline-from-center-border-thickness: 0.125rem;

.hover-underline-menu {
  width: 100%;

  .menu {
    background-color: $menu-underline-from-center-bg;

    a {
      color: $white;
      padding: 1.2rem 1.5rem;
    }

    .underline-from-center {
      position: relative;

      &::after {
        content: "";
        position: absolute;
        top: calc(100% - #{$menu-underline-from-center-border-thickness});
        border-bottom: $menu-underline-from-center-border-thickness solid $white;
        left: 50%;
        right: 50%;
        transition: all 0.5s ease;
      }

      &:hover::after {
        left: 0;
        right: 0;
        transition: all 0.5s ease;
      }
    }
  }
}


.hover-underline-menu {
  width: 100%;
}

.hover-underline-menu .menu {
  background-color: #2C3840;
}

.hover-underline-menu .menu a {
  color: #fefefe;
  padding: 1.2rem 1.5rem;
}

.hover-underline-menu .menu .underline-from-center {
  position: relative;
}

.hover-underline-menu .menu .underline-from-center::after {
  content: "";
  position: absolute;
  top: calc(100% - 0.125rem);
  border-bottom: 0.125rem solid #fefefe;
  left: 50%;
  right: 50%;
  transition: all 0.5s ease;
}

.hover-underline-menu .menu .underline-from-center:hover::after {
  left: 0;
  right: 0;
  transition: all 0.5s ease;
}

JS
$("[data-menu-underline-from-center] a").addClass("underline-from-center");