Creating a Animated Hoverable Navigation Menu Using HTML & CSS

Hello friend, I hope you are doing awesome. Today you will learn how to create a Sticky Navigation Menu Bar in HTML , CSS & Javascript. The interesting in this navbar menu is, the user-selected mode will not change while the webpage refreshed of the file is reopened. There are lots of Navigation Menu Bar but this navbar has some advanced features with beautiful UI and UX design.

A navigation bar is a horizontal section that contains navigation links aligned at the center of the webpage. The main motive of this navigation bar is to make it easier for users to be redirected from one webpage to another.

  1. HTML Structure

  2. Basic Styling

  3. Hover Effects

Other Beautiful Navebar

  1. HTML Structure

  2. <div class="nav-content"> : Defines the navigation container with a class for styling.

    <ul"> : Creates a list for the menu items.

    <li> <a href="#"> : Each list item contains a link to different sections of the page.

  3. CSS Styling

  4. Reset Styles : Remove default margins and paddings to start with a clean slate.

    Navebar Styling : Apply a background color to the navigation bar and clear floats to handle layout.

    Menu List Styling : Remove bullets and float list items horizontally.

    Link Styling : Style link to appeare as block element with padding and set text color and alignment.

    Hover Effecct : Apply hover animation line of the link on hover.

Output


output14
HTML
<!DOCTYPE html>
  <html lang="en">
    <head>
      <meta charset="UTF-8">
        <meta name="viewport" content ="width=device-width, initial-scale=1.0">
        <title>Navigation Bar Hover Animation HTML CSS </title>
    </head>
  <body>
       <nav>
         <div class="nav-content">
           <div class="logo">
               <a href ="#">BrodSchool</a>
       </div>
         <ul class="nav-link">
             <li><a href ="#">Home</a></li>
             <li><a href ="#">About</a></li>
             <li><a href ="#">Contact</a></li>
             <li><a href ="#">Services</a></li>
             <li><a href ="#">Help</a></li>
         </ul>
     </div>
       </nav>
           <div class="text">
               <h2>Sticky Navigation Bar</h2>
           </div>
   </body>
  </html>
CSS
/*default margins and paddings */
   * {
margin: 0;
padding: 0;
font-family: sans-serif;
box-sizing: border-box;
text-decoration: none;
   }
/*Style the menu items */
   nav {
   position: fixed ;
   top: 0 ;
   left: 0 ;
   padding: 20px ;
   transition : all 0.4s ease ;
   width: 100% ;
    }
   nav.sticky {
   background: #0fa566 ;
    padding : 15px 20px ;
    box-shadow : 0 6px 10px rgba(0, 0, 0, 0.2) ;
   }
   nav .nav-content {
   display: flex ;
   height : 100% ;
   max-width : 1200px ;
   margin : auto ;
   align-items : center ;
   justify-content : space-between ;
   }
   nav .logo a {
   font-weight: 600 ;
   font-size: 34px ;
   color: #d50c74 ;
   }
   nav .sticky .logo a {
   color: #fff ;
   }
   nav-content .nav-link {
   display: flex ;
   }
   nav-content .nav-link li{
   list-style: none ;
   margin: 0px  8px ;
   }
   nav-link li a{
   text-decoration: none ;
   Color: #0E2431 ;
   font-size: 18px ;
   font-weight: 500 ;
   padding:10px  4px ;
   transition: all 0.3s ease ;
   }
/* Change color on hover */
   nav-link li a :hover
{
   color:#4070f4 ;
   }
   nav.sticky .nav-link li a {
   color : #fff ;
   transition: all 0.4s ease ;
   }
   nav.sticky .nav-link li a:hover {
   color : #010204 ;
   }
   .home {
   height: 100vh ;
   width: 100% ;
   background-size: cover ;
   background-position: center ;
   background-attachment : fixed ;
   }
   h2 {
   font-size: 30px ;
   margin-bottom: 6px ;
   color: #d50c74 ;
   }
   .text {
   text-align: justify ;
   padding: 40px  80px ;
   box-shadow: -5px 0 8px rgba(0, 0, 0, 0.1) ;
   }
JavaScript
/*JavaScript stick */
<script>
let  nav=document.querySelector( "nav") ;
window.onscroll = function()
    {
if(document.documentElement.scrollTop > 20)
;
    {
nav.classList.add( 'sticky') ;
   }
    else {
     nav.classList.remove('sticky' ) ;
     }
   }
</script>



BrodSchool

Jagatpur,
Raebareli 229402, UP,  India
Amresh Kumar (Founder)
Phone: +91 9198 26 3500
Email: suportucracker@gmail.com

copyright © 2024 All Right Reserved.