22 Aug 2015

How to create PURE CSS DROP-DOWN MENU using just HTML and CSS

First create HTML file as given here:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="css/primary.css">
    </head>
    <body>
        <ul id="nav">
            <li>
                <a href="#">Home</a>
            </li>
            <li>
                <a href="#">Tutorials</a>
                <ul>
                    <li><a href="#">PHP</a></li>
                    <li><a href="#">CSS</a></li>
                    <li><a href="#">JAVASCRIPT</a></li>
                </ul>
            </li>
            <li>
                <a href="#">Contact</a>
                <ul>
                    <li><a href="#">My Email</a></li>
                    <li><a href="#">My Telephone</a></li>
                </ul>
            </li>
        </ul>
        <div>
            <br>
            <p>
                A paragraph of text here.
            </p>
        </div>
    </body>
</html>

Create CSS file as given here:

ul{
    list-style-type: none;
    padding: 0;
    margin: 0;
}
ul#nav li{
    background: #fff;
    float: left;
}
ul#nav li a{
    display: block;
    padding: 5px 10px;
    color: #000;
    text-decoration: none;
    border-bottom: 1px solid #ccc;
}
ul#nav li a:hover{
    background: #aaa;
}
ul#nav li ul li{
    float: none;
}
ul#nav li ul{
    position: absolute;
    display: none;
}
ul#nav li:hover ul{
    display: block;
}

Share:

0 comments:

Post a Comment