How to Create Dropdown Menu Using Only CSS and HTML
In this Tutorial you will learn on how to make a horizontal drop down menu using only CSS and HTML.
The best thing about this tutorial is I didn't used jquery and javascript for this menu. This is useful for thus programmer who want to make drop down menu without using jquery or javascript.
This menu is easy to integrate in your current website, enjoy this tutorial and fallow the steps bellow.
Creating Our HTML Display
The code bellow include the
- tag that display our menu. Copy the code bellow and save it as "index.php".
Creating Our CSS file
- <html>
- <head>
- <title>CSS Tutorial</title>
- </head>
- <body>
- <div id="menu">
- <ul>
- <li><a class="active" href="#">Menu 1</a>
- <ul>
- <li><a href="#">Menu 1.1</a></li>
- <li><a href="#">Menu 1.2</a>
- <ul>
- <li><a href="#">Menu 1.2.1</a></li>
- <li><a href="#">Menu 1.2.2</a></li>
- </ul>
- </li>
- </ul>
- </li>
- <li><a href="#">Menu 2</a>
- <ul>
- <li><a href="#">Menu 2.1</a></li>
- <li><a href="#">Menu 2.2</a>
- <ul>
- <li><a href="#">Menu 2.2.1</a></li>
- <li><a href="#">Menu 2.2.2</a></li>
- </ul>
- </li>
- </ul>
- </li>
- <li><a href="#">Menu 3</a></li>
- <li><a href="#">Menu 4</a></li>
- <li><a href="#">Menu 5</a></li>
- <li><a href="#">Menu 6</a></li>
- </ul>
- </div>
- </body>
- </html>
The file bellow include the CSS file that make our drop down menu. Copy the code bellow and save it as "style.css".
Designing Our Hover Effect
The code bellow will make as display our second level menu when the first level menu is hovered.
Designing Our First Level Menu- #menu ul li:hover > ul {
- display: block;
- }
- #menu ul li a:hover > ul {
- display: block;
- }
the code menu include the css property of our menu id define on our html file.
Designing Our Second Level Menu- #menu{
- width: auto;
- margin-top: 11px;
- }
- #menu ul ul {
- text-align:left !important;
- display: none;
- }
- #menu ul {
- list-style: none outside none;
- display: block;
- line-height:1px;
- padding:0;
- }
- #menu ul:after {
- display: block;
- }
- #menu ul li {
- float: left;
- position:relative;
- line-height:19px;
- }
- #menu > ul > li > a:hover {
- border-bottom: 4px solid #0097C4 !important;
- color:#0097C4;
- background-repeat: repeat;
- }
- #menu ul li a {
- color: #666666;
- font-size: 12px;
- padding: 27px 15px 33px 15px;
- text-decoration: none;
- text-transform: uppercase;
- border-bottom: 4px solid #00FF00 !important;
- display: block;
- position: relative;
- transition: all 0.2s linear 0s;
- position:relative;
- }
- #menu .active{
- border-bottom: 4px solid #0097C4 !important;
- color:#0097C4;
- background-repeat: repeat;
- }
Copy the code bellow and paste in our "style.css" file. The code bellow will design our second level menu and also include our hover effect to display our third level menu.
Designing Our Third Level Menu- #menu ul ul {
- border-top: 1px solid #ECECEC !important;
- position: absolute;
- z-index:1;
- background-color: #FFFFFF;
- border: 1px solid #ECECEC;
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
- margin-left:-1px !important;
- margin-top: 1px !important;
- }
- #menu ul ul li {
- float: none;
- position: relative;
- margin-right: 0 !important;
- width:230px;
- line-height:19px;
- margin: -1px 0 0;
- border-left: medium none;
- }
- #menu ul ul li a {
- font-size: 12px;
- padding: 8px 10px !important;
- text-transform: uppercase;
- border: medium none !important;
- border-bottom: 1px solid #ECECEC !important;
- }
- #menu > ul > li > ul > li > a:hover {
- color: #0097C4 !important;
- }
Copy the code bellow and paste in our "style.css" file. The code bellow will design our third level menu.
Summary of our style.css- #menu ul ul ul {
- position: absolute; left: 100%; top:0;
- width:230px;
- }
- #menu ul ul ul li a {
- padding: 8px 10px;
- }
- #menu ul ul ul li a:hover {
- color: #0097C4 !important;
- }
The code bellow is the correct arrange of our "style.css" file.
That's the steps on how to create a drop down menu with CSS and HTML only. Hope this code will help you.- #menu ul li:hover > ul {
- display: block;
- }
- #menu ul li a:hover > ul {
- display: block;
- }
- #menu{
- width: auto;
- margin-top: 11px;
- }
- #menu ul ul {
- text-align:left !important;
- display: none;
- }
- #menu ul {
- list-style: none outside none;
- display: block;
- line-height:1px;
- padding:0;
- }
- #menu ul:after {
- display: block;
- }
- #menu ul li {
- float: left;
- position:relative;
- line-height:19px;
- }
- #menu > ul > li > a:hover {
- border-bottom: 4px solid #0097C4 !important;
- color:#0097C4;
- background-repeat: repeat;
- }
- #menu ul li a {
- color: #666666;
- font-size: 12px;
- padding: 27px 15px 33px 15px;
- text-decoration: none;
- text-transform: uppercase;
- border-bottom: 4px solid #00FF00 !important;
- display: block;
- position: relative;
- transition: all 0.2s linear 0s;
- position:relative;
- }
- #menu .active{
- border-bottom: 4px solid #0097C4 !important;
- color:#0097C4;
- background-repeat: repeat;
- }
- #menu ul ul {
- border-top: 1px solid #ECECEC !important;
- position: absolute;
- z-index:1;
- background-color: #FFFFFF;
- border: 1px solid #ECECEC;
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
- margin-left:-1px !important;
- margin-top: 1px !important;
- }
- #menu ul ul li {
- float: none;
- position: relative;
- margin-right: 0 !important;
- width:230px;
- line-height:19px;
- margin: -1px 0 0;
- border-left: medium none;
- }
- #menu ul ul li a {
- font-size: 12px;
- padding: 8px 10px !important;
- text-transform: uppercase;
- border: medium none !important;
- border-bottom: 1px solid #ECECEC !important;
- }
- #menu > ul > li > ul > li > a:hover {
- color: #0097C4 !important;
- }
- #menu ul ul ul {
- position: absolute; left: 100%; top:0;
- width:230px;
- }
- #menu ul ul ul li a {
- padding: 8px 10px;
- }
- #menu ul ul ul li a:hover {
- color: #0097C4 !important;
- }
0 comments:
Post a Comment