What is a CSS Dropdown Menu?
If you are practicing web design, then you must have heard about the dropdown menu. The Dropdown Menu is a sub-menu that appears when visitors of any website hover over the main menu. When someone hovers over any nav item of the main menu, the submenu associated with it will appear on the main menu's bottom. So when a sub-menu appears, visitors can click on one of them to visit the other pages linked to it. Dropdown menus are mostly used for multi-page websites where lots of web pages were built during the development process. Most modern websites nowadays use dropdown menus on their website because it is the best way to organize the website content.Video Tutorial:
In this tutorial (Drop Down Menu using HTML and CSS), at first, In the HTML markup, we have taken a div named wrapper, which will act as a container of all the navigation content bars we are going to make. After that, we took an unordered list. To create a dropdown menu, we have taken another unordered list inside the Services nav item. To make another submenu under the design submenu, we also took another unordered list.
You may also like:
- Animated Profile Card Design
- Responsive Infinite Client Logo Slider
- Bootstrap Carousel with Text Animation
In the CSS part, we first discarded the default margin and padding of the document by providing a margin and padding of 0 to the universal selector. Then we gave a background image to the body and gave 100vh height to it. After that, we gave a custom width of 860px to the wrapper container and set it to the center by providing a margin of 0 and auto. Then we gave a custom width of 170px to all the li elements of the unordered list and gave them a relative position value. Then we did some basic styling for the li elements by giving them font size, color, line height, and so on. Initially, we set the dropdown unordered to display none. When someone hovers over the li element, the dropdown ul component will appear. we put a display block value to the main navbar li element on hover for this to happen. For the second dropdown menu under the first drop menu, we set an absolute position value with a top value of 0 and a margin-left value of 170px.
To create this snippet, you need to create two files. One of them is an HTML file, and the other is a CSS file. After that, you need to copy the HTML and CSS code, paste it to the appropriate files, and save them. If you want to download the code, you can do that by clicking the download button below this blog post.
ADD HTML:
ADD CSS:
I am a beginner. That was helpful
ReplyDeletereally appreciated , thanks a lot
ReplyDeletecss file is no linking with html file help!
ReplyDeleteHeight: 100vh
ReplyDeletevh means?
vh stands for viewport height and vw is for viewport width.
DeletePost a Comment
Please do not enter any spam link in the comment box.