How To Create CSS Magic Navigation Menu Indicator Using HTML CSS & JavaScript

   Project Introduction: In this project, we are going to implement a car running on a track using HTML and CSS with sound effects.

File structure:

  • . index.html
  • . style.css
  • .css/all.css

 HTML code: The following is the code for file “index.html” which is used in the above HTML code


<!DOCTYPE html>

<html lang="en" dir="ltr">

  <head>

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="style.css">

    <!--font awesome filup-->

    <link rel="stylesheet" href="css/all.css">

    <title>magic Indicator animation effect </title>


  <body>

    <div class="navigation">

      <ul>

        <li class="list active">

          <a href="#">

            <span class="icon"><i class="fas fa-home"></i></span>

            <span class="text">Home</span>

          </a>

        </li>

        <li class="list">

          <a href="#">

            <span class="icon"><i class="far fa-user"></i></span>

            <span class="text">Profile</span>

          </a>

        </li>

        <li class="list">

          <a href="#">

            <span class="icon"><i class="far fa-comment"></i></span>

            <span class="text">Massage</span>

          </a>

        </li>

        <li class="list">

          <a href="#">

            <span class="icon"><i class="fas fa-camera"></i></span>

            <span class="text">Photos</span>

          </a>

        </li>

        <li class="list">

          <a href="#">

            <span class="icon"><i class="fas fa-cog"></i></span>

            <span class="text">Setting</span>

          </a>

        </li>

        <div class="Indicator">


        </div>


      </ul>


    </div>



<script>

const list=document .querySelectorAll('.list');

function activeLink(){

  list .forEach((item)=>

item .classList .remove('active'));

this .classList .add('active');

}

list .forEach((item)=>

item .addEventListener('click',activeLink));


</script>

  </body>

</html>

style.css: The following is the code for file “style.css” which is used in the above HTML code. 


*{

  margin: 0;

  padding: 0;

  box-sizing: border-box;

  font-family: sans-serif;

}

:root{

  --clr:#02072A;

}

body{

  display: flex;

  justify-content: center;

  align-items: center;

  min-height: 100vh;

  background: var(--clr);

  font-size: 18px;

  text-transform: capitalize;

}

.navigation{

  width: 400px;

  height: 70px;

  background: #fff;

  position:relative;

  display: flex;

  justify-content: center;

  align-items: center;

  border-radius: 10px;


}

.navigation ul{

  display: flex;

  width: 350px;


}

.navigation ul li{

  position: relative;

  list-style: none;

  width: 70px;

  height: 70px;

  z-index: 1;

}

.navigation ul li a{

  position: relative;

  display: flex;

  justify-content: center;

  align-items: center;

  flex-direction: column;

  width: 100%;

  text-align: center;

  font-weight: 500;


}

.navigation ul li a .icon{

  position: relative;

  display: block;

  line-height: 75px;

  font-size: 1.5em;

  text-align: center;

  transition: 0.5s;

  color: var(--clr);

}

.navigation ul li.active a .icon{

  transform: translateY(-35px);

}

.navigation ul li a .text{

  position: absolute;

  color: var(--clr);

  font-weight: 400;

  font-size: 0.75;

  letter-spacing: 0.05em;

  transition: 0.5s;

  opacity: 0;

  transform: translateY(20px);

}

.navigation ul li.active a .text{

  opacity: 1;

  transform: translateY(10px);

}

.Indicator{

  position: absolute;

  top: -50%;

  width: 70px;

  height: 70px;

  background: #fff;

  border-radius: 50%;

  border: 6px solid var(--clr);

  transition: 0.5s;

}

.Indicator::before{

  content: '';

  position: absolute;

  top: 50%;

  left: -22px;

  height: 20px;

  width: 20px;

  background: transparent;

  border-top-right-radius: 20px;

  box-shadow: 0px -10px 0 0 var(--clr);

}

.Indicator::after{

  content: '';

  position: absolute;

  top: 50%;

  right: -22px;

  height: 20px;

  width: 20px;

  background: transparent;

  border-top-left-radius: 20px;

  box-shadow: 0px -10px 0 0 var(--clr);

}

.navigation ul li:nth-child(1).active ~ .Indicator{

  transform: translateX(calc(70px * 0));

}

.navigation ul li:nth-child(2).active ~ .Indicator{

  transform: translateX(calc(70px * 1));

}

.navigation ul li:nth-child(3).active ~ .Indicator{

  transform: translateX(calc(70px * 2));

}

.navigation ul li:nth-child(4).active ~ .Indicator{

  transform: translateX(calc(70px * 3));

}

.navigation ul li:nth-child(5).active ~ .Indicator{

  transform: translateX(calc(70px * 4));

}

Output :  




My facebook page link:

My YouTube video:





Post a Comment

0 Comments

Ad Code

Responsive Advertisement