Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to view a navbar menu when you hover over an element when using tailwindcss

I am trying to make a navbar menu item by using tailwind, here is the some snippet of the code

<!doctype html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
    
    <li class="w-22  hover:border-gray-700 border-transparent border-b-2 cursor-pointer">
        <a href="#">New & Featured</a>
        <ul class="absolute hidden left-2 mt-2 py-2 w-48 bg-white rounded-lg shadow-xl">
          <li class="block px-4 py-2 text-gray-800 hover:bg-indigo-600">Laptops</li>
          <li class="block px-4 py-2 text-gray-800 hover:bg-indigo-600"><a href="#">Monitors</a></li>
          <li class="block px-4 py-2 text-gray-800 hover:bg-indigo-600"><a href="#">Printers</a></li>
        </ul>
      </li>
</body>
</html>

I would like that when I hover on the element News & Features the drop down element element is seen, when I hover out it should return to its default hidden.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

<!doctype html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.tailwindcss.com"></script>
  <style>
    .dropdown:hover .dropdown-menu {
      display: block;
    }
    .dropdown-menu {
      display: none;
    }
  </style>
</head>
<body>
  <nav>
    <ul>
      <li class="relative dropdown">
        <a href="#" class="inline-block">New & Featured</a>
        <ul class="absolute left-0 w-48 py-2 bg-white rounded-lg shadow-xl dropdown-menu">
          <li class="block px-4 py-2 text-gray-800 hover:bg-indigo-600">Laptops</li>
          <li class="block px-4 py-2 text-gray-800 hover:bg-indigo-600"><a href="#">Monitors</a></li>
          <li class="block px-4 py-2 text-gray-800 hover:bg-indigo-600"><a href="#">Printers</a></li>
        </ul>
      </li>
    </ul>
  </nav>
</body>
</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading