Create a dropdown menu with HTML and CSS

make a dropdown menu with HTML and CSS

edited by AlfredoBot

, Maluniu, proofreader

2 methods:

HTMLCSS a dropdown menu gives a clear and hierarchical listing of all main and subcomponents of Web page To the subcomponents appear’s. you just have to hover your mouse above the main parts. Follow the steps below to build your own menu, adapted to your wishes. In addition, at every step images added to make it more clearly. We’ll start with the HTML-code, followed by applying

CSS for formatting.

Ad

Steps method 1 of 2:

HTML

 make a dropdown menu with HTML and CSS
1

create a framework in HTML for the CSS menu. We use \ ‘ \ ‘ div with class = ” nav ” . As you can see on the left is the HTML code a simple list of UL’s for the main components of the menu.

Ad

 make a dropdown menu with HTML and CSS
2 add links for the main parts. At this time, it’s not more than a simple unordered list UL with 4 list items.

 make a dropdown menu with HTML and CSS
3

add links for the submenu under ” About Us ” by adding an unordered list inside LI from the main menu.

 make a dropdown menu with HTML and CSS
4

add CSS to your HTML. What we have now is a structure in HTML in a convenient layout of links, in which the sub menu’s in a clear relationship are at the main menu. We are now going to attach an external CSS file, by adding the following link in the \ ‘ head \ ‘ section of the

code:

Method 2 of 2:

CSS

 make a dropdown menu with HTML and CSS
1

create a CSS file. Now we are done with the HTML structure, we can continue with the formatting through CSS, to make sure that it really functions and menu will look like as we want. Using CSS-selectors we can appeal to individual elements in the HTML structure without the need for additional ID’s or classes. We hide submenu’s by the UL’s within a LI with the Declaration display: none; To ensure that the menu’s tevoorschijnkomen again if you exceed the LI is floating, they must be converted to \ ‘ block elements \ ‘; the > ensures that only the child-UL of the LI above which is floated along, is addressed.

 make a dropdown menu with HTML and CSS
2

the formatting of the main menu with CSS. position: relative; this positioning you compared to the main menu the submenu (main nav bar) display: inline-block; change the width of the menu to fit.

 make a dropdown menu with HTML and CSS
3

Add a gradient and change the font color when you hovers over an item. The following code is added to the LI tags, making changes the background color of the link and the text becomes white.

 make a dropdown menu with HTML and CSS
4

change the formatting of the submenu’s. Currently inherit the submenu’s parent elements style \ ‘ \ ‘ (the main menu). We want them vertically and placed under the main menu list.

 make a dropdown menu with HTML and CSS

5 Positioning your dropdown menu and with this line from the list item. This allows you to also remove the gray background. position: relative; code has been added to the top list items position: absolute; code was added in the list item placed within the relatively.

Ad

This article is automatically posted by WP-Auto Post: WordPress pluginArticle Source Settings, WP-Autoblog Auto Post


Leave a Reply

Your email address will not be published. Required fields are marked *