- Main Navigation
- Tabs
- Popup Ups
- Search Bar
- Side Navigation
- Form Control
Main Navigation or Main Menu
How to build main navigation as shown in the above image?
Write HTML code
There is no particular rule to follow while writing HTML code, you can write the code in your own way but the best way to make navigation is to use an unordered list, as the menu items are list of pages that a user can navigate to.
Logically, there are three levels of this navigation as shown below:
So, the first level can be written as:
As Menu Item 4 is having a sub navigation, we will add an unordered list inside the Menu Item 4's container li element as shown in the below code:
Write CSS
The best way to make an unordered list to look like the level 1 navigation is to use CSS properties like display table and table-cell. So, the CSS code for the first level navigation would be as below:
The second level ul lies absolutely below its parent li and is in alignment with the parent li. This can be achieved by making second level ul's position absolute with respect to its parent li i.e by making the parent li's position relative. So, now the code would be:
Second and third level navigation has some white border and the third level navigation has a box-shadow. Border can be added commonly to the second and third level li.
Now, the only thing left is the arrow and the lines seperating the first-level navigation items. For this I have used the before and after pseudo selectors with the first level lis. I have added a class to identify the li elements having children, to add the arrows. Here is the code for that:
CSS Code for the line of separation in the first level navigation
CSS code to create arrows for the li elements having children |
To hide show the navigation, we have to write some lines of javascript. We will be doing it once we go through the basics of javascript.
For any queries or feedback, write to info@beawesomewithprogramming.co.in