Open Menu dzosoft
Close Menu dzosoft

   TOUT SUR L'INFORMATIQUE ET LA TECHNOLOGIE


                             




Japanese ritual of tranquility and... slim figure!

Publish perfectly-optimized content in 1-click



 
 
 

How to create menu with css and javascript

 

 

Step 1

 

Cascading Style Sheets (CSS)

 
We use the w3.css file from w3school


<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">


 

Step 2

 

Javascript

 

The first function HideAll allows us to hide all the menu (Menu1, Menu 2 and Menu3)
just set the className to empty, If we want show the menu just set the className to " w3-show "


function HideAll() { var x; for(i=1;i<4;i++) { x = document.getElementById("Menu"+i); x.className = x.className.replace(" w3-show", ""); }
}


The function showMenu1 (the same with showMenu2 and showMenu3) show the menu (the div with id "Menu1")


function showMenu1() { HideAll(); var x = document.getElementById("Menu1"); if (x.className.indexOf("w3-show") == -1) { x.className += " w3-show"; } else { x.className = x.className.replace(" w3-show", ""); } } function showMenu2() { HideAll(); var x = document.getElementById("Menu2"); if (x.className.indexOf("w3-show") == -1) { x.className += " w3-show"; } else { x.className = x.className.replace(" w3-show", ""); } } function showMenu3() { HideAll(); var x = document.getElementById("Menu3"); if (x.className.indexOf("w3-show") == -1) { x.className += " w3-show"; } else { x.className = x.className.replace(" w3-show", ""); } }


 

Step 3

 

HTML

 

<div class="w3-dropdown-click">
   <button onclick="showMenu1()" class="w3-button">Menu 1</button>
   <div id="Menu1" class="w3-dropdown-content w3-bar-block w3-animate-zoom">
       <a href="#" class="w3-bar-item w3-button">Link 1</a>
       <a href="#" class="w3-bar-item w3-button">Link 2</a>
       <a href="#" class="w3-bar-item w3-button">Link 3</a>
   </div>
   </div>
<div class="w3-dropdown-click">   
   <button onclick="showMenu2()" class="w3-button">Menu 2>/button>
   <div id="Menu2" class="w3-dropdown-content w3-bar-block w3-animate-zoom">
       <a href="#" class="w3-bar-item w3-button">Link 1>/a>
       <a href="#" class="w3-bar-item w3-button">Link 2>/a>
       <a href="#" class="w3-bar-item w3-button">Link 3>/a>
   </div>
</div>
<div class="w3-dropdown-click">   
   <button onclick="showMenu3()" class="w3-button">Menu 3>/button>
   <div id="Menu3" class="w3-dropdown-content w3-bar-block w3-animate-zoom">
       <a href="#" class="w3-bar-item w3-button">Link 1>/a>
       <a href="#" class="w3-bar-item w3-button">Link 2>/a>
       <a href="#" class="w3-bar-item w3-button">Link 3>/a>
   </div>
</div>



Download the example


Happy Coding! 😇

También te puede interesar


Comment pouvons-nous faire des animations avec uniquement CSS

Comment créer un menu horizontal en CSS

Comment arrondir un rayon de bordure en CSS ?

Comment créer un formulaire d'inscription avec HTML et CSS

Comment créer un site Web réactif

Comment créer un effet GLITCH avec CSS

Comment changer le style des barres de défilement

Comment créer un effet Focus au survol en utilisant CSS

Comment créer un pied de page avec Bootstrap : tutoriel et exemple


Leave comment
          

Enregistrez le pseudo et l'e-mail dans ce navigateur pour la prochaine fois.



Cargando...     

NICOTINE FREE