{"componentChunkName":"component---src-templates-blog-js","path":"/blog/how-to-create-tailwind-css-dropdown/","result":{"data":{"site":{"siteMetadata":{"title":"Resources to help developers | Contrast | Devwares"}},"mdx":{"id":"031a03fc-c219-55fa-adda-bfb88c0fd255","excerpt":"Tailwind Dropdowns Tailwind CSS is a powerful and versatile tool that can help you create visually appealing and feature-rich websites. One of the most popular…","body":"var _excluded = [\"components\"];\nfunction _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }\nfunction _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }\nfunction _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }\n/* @jsxRuntime classic */\n/* @jsx mdx */\n\nvar _frontmatter = {\n  \"title\": \"How to create Tailwind CSS dropdown\",\n  \"lastUpdated\": \"20 May 2024\",\n  \"date\": \"2021-01-10T02:16:04+01:00\",\n  \"metaTitle\": \"How to create Tailwind CSS dropdown\",\n  \"metaDescription\": \"Dropdowns are very important for responsive websites and applications. We shall look at the ways to create this tailwind css dropdown example\",\n  \"type\": \"blog\",\n  \"author\": \"Emmanuel Chinonso\",\n  \"role\": \"Technical Writer\",\n  \"authorImage\": \"/blog/author/author_emmanuel.jpg\",\n  \"image\": \"./_/images/how-to-create-tailwind-css-dropdown.png\",\n  \"tags\": [\"tailwind css\", \"bootstrap\", \"bootstrap 5 alpha\"],\n  \"previousTitle\": \"How to create Tailwind CSS Components for your Website\",\n  \"previousPath\": \"how-to-create-tailwind-css-components-for-your-website\",\n  \"nextTitle\": \"How to create Tailwind CSS Modal:A Step-by-Step Guide\",\n  \"nextPath\": \"how-to-create-tailwind-css-modal\",\n  \"blogtype\": \"tailwindcss\",\n  \"canonicalUrl\": \"https://windframe.dev/blog/how-to-create-tailwind-css-dropdown\"\n};\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n    props = _objectWithoutProperties(_ref, _excluded);\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"h1\", null, \"Tailwind Dropdowns\"), mdx(\"p\", null, \"Tailwind CSS is a powerful and versatile tool that can help you create visually appealing and feature-rich websites. One of the most popular features of Tailwind is its ability to create dropdown menus. Dropdowns allow you to provide additional content to users without taking up too much space on the page. In this blog, we will walk through the steps to create a Tailwind CSS dropdown menu.\"), mdx(\"h2\", null, \"Table of content\"), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Installing Tailwind CSS\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Setting up the Html Structure.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Adding the Classes to the Tailwind dropdown\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Overview of Tailwind CSS dropdown menu\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Conclusion\")), mdx(\"h2\", null, \"Installing Tailwind CSS\"), mdx(\"p\", null, \"We have to install Tailwind CSS before we can start building our Tailwind dropdown menu. There are many ways you can do this. You can check our post here to understand it \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/blog/How-to-use-tailwind-css-in-HTML\"\n  }, \"better\"), \".\"), mdx(\"h2\", null, \"Setting up the Html Structure.\"), mdx(\"p\", null, \"The first step to creating a Tailwind CSS dropdown is setting up the HTML structure. You will need to create a div container with a class of \\u201Cdropdown\\u201D. Inside this div, you should create two other divs, one for the dropdown trigger and one for the dropdown menu. The trigger div should contain an anchor tag with an id, class, and aria-haspopup attribute. The menu div should contain a list of links, each with its own class of \\u201Cdropdown-item\\u201D.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-html\"\n  }, \"<!DOCTYPE html>\\n<html lang=\\\"en\\\">\\n  <head>\\n    <meta charset=\\\"UTF-8\\\" />\\n    <meta http-equiv=\\\"X-UA-Compatible\\\" content=\\\"IE=edge\\\" />\\n    <meta name=\\\"viewport\\\" content=\\\"width=device-width, initial-scale=1.0\\\" />\\n    <title>Drop down meanu</title>\\n    <link rel=\\\"stylesheet\\\" href=\\\"style.css\\\" />\\n  </head>\\n  <body>\\n    <div>\\n    <div>\\n        <button\\n            >Dropdown\\n            <svg class=\\\"h-5 w-5 text-gray-800\\\" xmlns=\\\"http://www.w3.org/2000/svg\\\" viewBox=\\\"0 0 20 20\\\"\\n                fill=\\\"currentColor\\\"><path fill-rule=\\\"evenodd\\\"\\n                    d=\\\"M5.293 7.293a1 1 0 011.414 0L10\\n                    10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z\\\"\\n                    clip-rule=\\\"evenodd\\\" /></svg>\\n        </button>\\n        <div>\\n        </div>\\n\\n        <div >\\n            <a href=\\\"#\\\" >\\n                your profile\\n            </a>\\n            <a href=\\\"#\\\" >\\n                Your projects\\n            </a>\\n            <a href=\\\"#\\\">\\n                Help\\n            </a>\\n            <a href=\\\"#\\\" >\\n                Settings\\n            </a>\\n            <a href=\\\"#\\\" >\\n                Sign Out\\n            </a>\\n        </div>\\n    </div>\\n</div>\\n\\n</body>\\n</html>\\n  </body>\\n</html>\\n\")), mdx(\"p\", null, \"In the code above, we added the link to the Tailwind CSS stylesheet file. Which we have already installed and set up as the style.css file. The necessary divs and struture for our Tailwind dropdown menu was also set up.\"), mdx(\"h2\", null, \"Adding the Classes to the Tailwind dropdown\"), mdx(\"p\", null, \"Since the skeleton has been created and you have placed the necessary \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"divs\"), \", it will be wise now to add some classes to the Tailwind dropdown. These Tailwind classes allow for your designs and dropdowns to occur smoothly. The Javascript required for these functions to happen was also included at the bottom of the Html file.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-html\"\n  }, \"<div class=\\\"flex justify-center h-screen\\\">\\n    <div x-data=\\\"{ dropdownOpen: true }\\\" class=\\\"relative my-32\\\">\\n        <button @click=\\\"dropdownOpen = !dropdownOpen\\\"\\n            class=\\\"relative z-10 block rounded-md p-2\\n            bg-blue-600 text-gray-200\\n             px-6 text-sm py-3 overflow-hidden focus:outline-none focus:border-white\\\">Dropdown\\n            <svg class=\\\"h-5 w-5 text-gray-800\\\" xmlns=\\\"http://www.w3.org/2000/svg\\\" viewBox=\\\"0 0 20 20\\\"\\n                fill=\\\"currentColor\\\"><path fill-rule=\\\"evenodd\\\"\\n                    d=\\\"M5.293 7.293a1 1 0 011.414 0L10\\n                    10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z\\\"\\n                    clip-rule=\\\"evenodd\\\" /></svg>\\n        </button>\\n\\n        <div x-show=\\\"dropdownOpen\\\" @click=\\\"dropdownOpen = false\\\" class=\\\"fixed inset-0 h-full w-full z-10\\\">\\n\\n        </div>\\n\\n        <div x-show=\\\"dropdownOpen\\\" class=\\\"absolute right-0 mt-2 py-2 w-48 bg-white rounded-md\\n        shadow-xl z-20\\\">\\n            <a href=\\\"#\\\" class=\\\"block px-4 py-2 text-sm capitalize text-gray-800 hover:bg-indigo-500\\n            hover:text-white\\\">\\n                your profile\\n            </a>\\n            <a href=\\\"#\\\" class=\\\"block px-4 py-2 text-sm capitalize text-gray-800 hover:bg-indigo-500\\n            hover:text-white\\\">\\n                Your projects\\n            </a>\\n            <a href=\\\"#\\\" class=\\\"block px-4 py-2 text-sm capitalize text-gray-800 hover:bg-indigo-500\\n            hover:text-white\\\">\\n                Help\\n            </a>\\n            <a href=\\\"#\\\" class=\\\"block px-4 py-2 text-sm capitalize text-gray-800 hover:bg-indigo-500\\n            hover:text-white\\\">\\n                Settings\\n            </a>\\n            <a href=\\\"#\\\" class=\\\"block px-4 py-2 text-sm capitalize text-gray-800 hover:bg-indigo-500\\n            hover:text-white\\\">\\n                Sign Out\\n            </a>\\n        </div>\\n    </div>\\n</div>\\n<script src=\\\"https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js\\\" defer></script>\\n</body>\\n</html>\\n\")), mdx(\"p\", null, \"In the code above, we had the Tailwind dropdown menu set up along with the necessary Tailwind CSS classes.\"), mdx(\"h2\", null, \"Overview of Tailwind CSS dropdown menu\"), mdx(\"p\", null, \"Our entire code will look like the code below\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-html\"\n  }, \"<!DOCTYPE html>\\n<html lang=\\\"en\\\">\\n  <head>\\n    <meta charset=\\\"UTF-8\\\" />\\n    <meta http-equiv=\\\"X-UA-Compatible\\\" content=\\\"IE=edge\\\" />\\n    <meta name=\\\"viewport\\\" content=\\\"width=device-width, initial-scale=1.0\\\" />\\n    <title>Drop down meanu</title>\\n    <link rel=\\\"stylesheet\\\" href=\\\"style.css\\\" />\\n  </head>\\n  <body>\\n    <div class=\\\"flex justify-center h-screen\\\">\\n      <div x-data=\\\"{ dropdownOpen: true }\\\" class=\\\"relative my-32\\\">\\n        <button\\n          @click=\\\"dropdownOpen = !dropdownOpen\\\"\\n          class=\\\"relative z-10 block rounded-md p-2  \\n          bg-blue-600\\n           text-gray-200  px-6 text-sm py-3 overflow-hidden \\n           focus:outline-none focus:border-white\\\"\\n        >\\n          Dropdown\\n          <svg\\n            class=\\\"h-5 w-5 text-gray-800\\\"\\n            xmlns=\\\"http://www.w3.org/2000/svg\\\"\\n            viewBox=\\\"0 0 20 20\\\"\\n            fill=\\\"currentColor\\\"\\n          >\\n            <path\\n              fill-rule=\\\"evenodd\\\"\\n              d=\\\"M5.293 7.293a1 1 0 011.414 0L10 \\n              10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z\\\"\\n              clip-rule=\\\"evenodd\\\"\\n            />\\n          </svg>\\n        </button>\\n\\n        <div\\n          x-show=\\\"dropdownOpen\\\"\\n          @click=\\\"dropdownOpen = false\\\"\\n          class=\\\"fixed inset-0 h-full w-full z-10\\\"\\n        ></div>\\n\\n        <div\\n          x-show=\\\"dropdownOpen\\\"\\n          class=\\\"absolute right-0 mt-2 py-2 w-48 bg-white rounded-md shadow-xl z-20\\\"\\n        >\\n          <a\\n            href=\\\"#\\\"\\n            class=\\\"block px-4 py-2 text-sm capitalize text-gray-800 hover:bg-indigo-500 hover:text-white\\\"\\n          >\\n            your profile\\n          </a>\\n          <a\\n            href=\\\"#\\\"\\n            class=\\\"block px-4 py-2 text-sm capitalize text-gray-800 hover:bg-indigo-500 hover:text-white\\\"\\n          >\\n            Your projects\\n          </a>\\n          <a\\n            href=\\\"#\\\"\\n            class=\\\"block px-4 py-2 text-sm capitalize text-gray-800 hover:bg-indigo-500 hover:text-white\\\"\\n          >\\n            Help\\n          </a>\\n          <a\\n            href=\\\"#\\\"\\n            class=\\\"block px-4 py-2 text-sm capitalize text-gray-800 hover:bg-indigo-500 hover:text-white\\\"\\n          >\\n            Settings\\n          </a>\\n          <a\\n            href=\\\"#\\\"\\n            class=\\\"block px-4 py-2 text-sm capitalize text-gray-800 hover:bg-indigo-500 hover:text-white\\\"\\n          >\\n            Sign Out\\n          </a>\\n        </div>\\n      </div>\\n    </div>\\n    <script\\n      src=\\\"https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js\\\"\\n      defer\\n    ></script>\\n  </body>\\n</html>\\n\")), mdx(\"p\", null, \"The Tailwind CSS dropdown menu will like the images below.\"), mdx(\"p\", null, mdx(\"span\", {\n    parentName: \"p\",\n    \"className\": \"gatsby-resp-image-wrapper\",\n    \"style\": {\n      \"position\": \"relative\",\n      \"display\": \"block\",\n      \"marginLeft\": \"auto\",\n      \"marginRight\": \"auto\",\n      \"maxWidth\": \"1035px\"\n    }\n  }, \"\\n      \", mdx(\"a\", {\n    parentName: \"span\",\n    \"className\": \"gatsby-resp-image-link\",\n    \"href\": \"/static/a47003d7ea36a00b9e3a1be916af3a93/f2f8c/dropdown-menu.png\",\n    \"style\": {\n      \"display\": \"block\"\n    },\n    \"target\": \"_blank\",\n    \"rel\": \"noopener\"\n  }, \"\\n    \", mdx(\"span\", {\n    parentName: \"a\",\n    \"className\": \"gatsby-resp-image-background-image\",\n    \"style\": {\n      \"paddingBottom\": \"28.95752895752896%\",\n      \"position\": \"relative\",\n      \"bottom\": \"0\",\n      \"left\": \"0\",\n      \"backgroundImage\": \"url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAVElEQVQY02P4jwf8+/cPhf8XjY8NMOCSgGl+9env/+4dX/6ff/SLKEMJGvjk/Z//qYs+/j948ydE/C+ZBlLdyzDDQPSvP//gLvtHrpeRDYRhYgwEAC1u2xKvbwhcAAAAAElFTkSuQmCC')\",\n      \"backgroundSize\": \"cover\",\n      \"display\": \"block\"\n    }\n  }), \"\\n  \", mdx(\"img\", {\n    parentName: \"a\",\n    \"className\": \"gatsby-resp-image-image\",\n    \"alt\": \"dropdown\",\n    \"title\": \"dropdown\",\n    \"src\": \"/static/a47003d7ea36a00b9e3a1be916af3a93/e3189/dropdown-menu.png\",\n    \"srcSet\": [\"/static/a47003d7ea36a00b9e3a1be916af3a93/a2ead/dropdown-menu.png 259w\", \"/static/a47003d7ea36a00b9e3a1be916af3a93/6b9fd/dropdown-menu.png 518w\", \"/static/a47003d7ea36a00b9e3a1be916af3a93/e3189/dropdown-menu.png 1035w\", \"/static/a47003d7ea36a00b9e3a1be916af3a93/f2f8c/dropdown-menu.png 1490w\"],\n    \"sizes\": \"(max-width: 1035px) 100vw, 1035px\",\n    \"style\": {\n      \"width\": \"100%\",\n      \"height\": \"100%\",\n      \"margin\": \"0\",\n      \"verticalAlign\": \"middle\",\n      \"position\": \"absolute\",\n      \"top\": \"0\",\n      \"left\": \"0\"\n    },\n    \"loading\": \"lazy\"\n  }), \"\\n  \"), \"\\n    \")), mdx(\"p\", null, \"once you click on the dropdown button, you will see the list on the dropdown. Just like the image below.\"), mdx(\"p\", null, mdx(\"span\", {\n    parentName: \"p\",\n    \"className\": \"gatsby-resp-image-wrapper\",\n    \"style\": {\n      \"position\": \"relative\",\n      \"display\": \"block\",\n      \"marginLeft\": \"auto\",\n      \"marginRight\": \"auto\",\n      \"maxWidth\": \"1035px\"\n    }\n  }, \"\\n      \", mdx(\"a\", {\n    parentName: \"span\",\n    \"className\": \"gatsby-resp-image-link\",\n    \"href\": \"/static/f54ffa804f7b039476f7b693d9480fc6/c211c/drop-down-menu.png\",\n    \"style\": {\n      \"display\": \"block\"\n    },\n    \"target\": \"_blank\",\n    \"rel\": \"noopener\"\n  }, \"\\n    \", mdx(\"span\", {\n    parentName: \"a\",\n    \"className\": \"gatsby-resp-image-background-image\",\n    \"style\": {\n      \"paddingBottom\": \"37.83783783783784%\",\n      \"position\": \"relative\",\n      \"bottom\": \"0\",\n      \"left\": \"0\",\n      \"backgroundImage\": \"url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAYAAAD5nd/tAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAi0lEQVQoz2P4jwX8+/cPTsPYIPAXSRwXYMAlgaxpzrFv/9dd+IFiKEkGwgz79evf//NXfv33qn/3v3zBZ7DYn7//SHchTMPPn//+X7ry5f+jO7/+f3j9FyTzHyRFhpchGkH079/fQB6FipEZhsgav3799v/btx9A7//GGlFkRQqyIf8oiRR01xBjKAAD+3hACgowLAAAAABJRU5ErkJggg==')\",\n      \"backgroundSize\": \"cover\",\n      \"display\": \"block\"\n    }\n  }), \"\\n  \", mdx(\"img\", {\n    parentName: \"a\",\n    \"className\": \"gatsby-resp-image-image\",\n    \"alt\": \"dropdown\",\n    \"title\": \"dropdown\",\n    \"src\": \"/static/f54ffa804f7b039476f7b693d9480fc6/e3189/drop-down-menu.png\",\n    \"srcSet\": [\"/static/f54ffa804f7b039476f7b693d9480fc6/a2ead/drop-down-menu.png 259w\", \"/static/f54ffa804f7b039476f7b693d9480fc6/6b9fd/drop-down-menu.png 518w\", \"/static/f54ffa804f7b039476f7b693d9480fc6/e3189/drop-down-menu.png 1035w\", \"/static/f54ffa804f7b039476f7b693d9480fc6/c211c/drop-down-menu.png 1502w\"],\n    \"sizes\": \"(max-width: 1035px) 100vw, 1035px\",\n    \"style\": {\n      \"width\": \"100%\",\n      \"height\": \"100%\",\n      \"margin\": \"0\",\n      \"verticalAlign\": \"middle\",\n      \"position\": \"absolute\",\n      \"top\": \"0\",\n      \"left\": \"0\"\n    },\n    \"loading\": \"lazy\"\n  }), \"\\n  \"), \"\\n    \")), mdx(\"h2\", null, \"Conclusion\"), mdx(\"p\", null, \"The Tailwind CSS dropdown menu will certainly come in handy when building some navigation for your web applications. In this article, we explored an example of how to build a Tailwind CSS dropdown menu with Tailwind CSS.\"));\n}\n;\nMDXContent.isMDXComponent = true;","frontmatter":{"title":"How to create Tailwind CSS dropdown","date":"January 10, 2021","image":null,"imageExternal":null,"lastUpdated":"20 May 2024","author":"Emmanuel Chinonso","role":"Technical Writer","authorImage":"/blog/author/author_emmanuel.jpg","metaTitle":"How to create Tailwind CSS dropdown","metaDescription":"Dropdowns are very important for responsive websites and applications. We shall look at the ways to create this tailwind css dropdown example","previousTitle":"How to create Tailwind CSS Components for your Website","previousPath":"how-to-create-tailwind-css-components-for-your-website","nextTitle":"How to create Tailwind CSS Modal:A Step-by-Step Guide","nextPath":"how-to-create-tailwind-css-modal","blogtype":"tailwindcss"},"fields":{"slug":"/how-to-create-tailwind-css-dropdown/"}},"previous":null,"next":null},"pageContext":{"id":"031a03fc-c219-55fa-adda-bfb88c0fd255"}},"staticQueryHashes":["2619113677","2619113677","2619113677","2619113677","2619113677","2619113677","3309287076","3706406642","3706406642","4045616534","4045616534","956403285","956403285"]}