• Home
  • /
  • Pure CSS Animated Tab Menu – No JavaScript Needed!

Pure CSS Animated Tab Menu – No JavaScript Needed!

HTML

				
					<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>LearnWithArshyan - How to Build a Pure CSS Animated Tab Menu</title>
  <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css'><link rel="stylesheet" href="./style.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- partial:index.partial.html -->
<nav class="nav">
  <input id="menu" type="checkbox">
  <label for="menu">Menu</label>
  <ul class="menu">
    <li>
      <a href="#0">
        <span>About</span>
        <i class="fas fa-address-card" aria-hidden="true"></i>
      </a>
    </li>
    <li>
      <a href="#0">
        <span>Projects</span>
        <i class="fas fa-tasks" aria-hidden="true"></i>
      </a>
    </li>
    <li>
      <a href="#0">
        <span>Clients</span>
        <i class="fas fa-users" aria-hidden="true"></i>
      </a>
    </li>
    <li>
      <a href="#0">
        <span>Contact</span>
        <i class="fas fa-envelope-open-text" aria-hidden="true"></i>
      </a>
    </li>
  </ul>
</nav>

<div class='code-block code-block-2' style='margin: 8px 0; clear: both;'>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2094722033678002"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-2094722033678002"
     data-ad-slot="2248279416"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></div>
<p class="notification">Click on the Menu</p>

  
</body>
</html>
				
			

CSS

				
					/* RESET/BASIC STYLES
–––––––––––––––––––––––––––––––––––––––––––––––––– */
@import url('https://fonts.googleapis.com/css2?family=Inter&display=swap');

:root {
  --white: #ffffff;
  --light-grey: #edf0f1;
  --violet: rgb(0, 255, 21);
  --dark-violet: rgb(0, 255, 21);
  --black: rgb(0, 255, 21);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

ul {
  list-style: none;
}

a {
  color: inherit;
  text-decoration: none;
}

body {
  font-family: "Inter", sans-serif;
  text-align: center;
  padding: 0 20px;
  background: #06020f;
  color: var(--white);
}

.notification {
  position: absolute;
  top: 0;
  right: 0;
  padding: 10px;
  background: var(--violet);
}

/* MAIN STYLES
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.nav {
  position: relative;
  display: flex;
  justify-content: center;
  max-width: 400px;
  padding-bottom: 20px;
  border-radius: 5px 5px 25px 25px;
  margin: 300px auto 0;
  background: var(--white);
  box-shadow: rgb(50 50 93 / 10%) 0 30px 60px -12px,
    rgb(0 0 0 / 15%) 0 18px 36px -18px;
}

.nav [type="checkbox"] {
  position: absolute;
  left: -9999px;
}

.nav [type="checkbox"] + label {
  position: relative;
  width: 75px;
  height: 75px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  z-index: 1;
  background: var(--violet);
  border-radius: 50%;
  transform: translateY(-50%);
  transition: all 0.2s;
}

.nav [type="checkbox"] + label:hover {
  background: var(--dark-violet);
}

.menu li {
  position: absolute;
  top: -25px;
  left: 50%;
  transform: translateX(-50%);
  transition: all 0.4s;
}

.menu li:nth-child(1) {
  transition-delay: 0.2s;
}

.menu li:nth-child(2) {
  transition-delay: 0.15s;
}

.menu li:nth-child(3) {
  transition-delay: 0.1s;
}

.menu li:nth-child(4) {
  transition-delay: 0.05s;
}

.menu li a {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--violet);
}

.menu li a span {
  position: absolute;
  top: 0;
  left: 0;
  transform: translateY(calc(-100% - 5px));
  width: 100%;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  color: var(--white);
  font-weight: bold;
}

.nav input:checked + label {
  background: var(--black);
  transform: translateY(calc(-50% + 4px));
}

.nav input:checked ~ .menu li:nth-child(1) {
  top: -210px;
  transition-delay: 0.1s;
}

.nav input:checked ~ .menu li:nth-child(2) {
  top: -160px;
  left: calc(50% - 75px);
  transition-delay: 0.2s;
}

.nav input:checked ~ .menu li:nth-child(3) {
  top: -160px;
  left: calc(50% + 75px);
  transition-delay: 0.3s;
}

.nav input:checked ~ .menu li:nth-child(4) {
  top: -110px;
  transition-delay: 0.4s;
}

.nav input:checked ~ .menu li a span {
  opacity: 1;
  transition-delay: 0.9s;
}


				
			

Share this post

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top