Display Submenu On Mouse Hover in HTML and CSS

Hello friends how are you , Today in this post "Display Submenu On Mouse Hover" i am going to teach you how you can Show and Hide submenu on mouse hover using very simple lines of HTML and CSS code. If you want to create a website then this post can help you to create menu , submenu and show and hide submenu effect in a very simple way. You can also customize this submenu as per your requirement, So Let's start

If you want to understand this through video then watch this video i have explained it step by step live

Now i am going to explain step by step.

Step 1:Create a Folder: Just  create a folder with any name and in any drive in your system, In my case my folder name is Submenu.

Step 2:Create an HTML file: Now open notepad and type the below code or you can copy this code for your personal use

<html>
    <head>
        <title>KrazyProgrammer</title>
        <style>
            body{
                margin: 0;
                padding: 0;
                font-family: cursive;
                background-image: url('bg.jpg');
            }
            ul{
                padding: 0;
                list-style-type: none;
                background-color: #0b121b;
                margin-top: 0;
            }
            ul li{
                display: inline-block;
                position: relative;
                line-height: 20px;
                text-align: left;
                width: 120px;
            }
            ul li ul li{
                border-bottom: 1px solid white;
            }
            ul li a{
                display: block;
                padding: 8px 25px;
                color: white;
                text-decoration: none;
            }
            ul li a:hover{
                color: white;
                background-color: orangered;
            }
            ul li ul.name
            {
                min-width: 100%;
                background-color: rgba(11,18,27,0.8);
                color: white;
                display: none;
                position: absolute;
                z-index: 999;
                left: 0;
            }
            ul li ul li ul.topic
            {
                display: none;
            }
            ul li ul li:hover ul.topic
            {
                display: block;
                left: 100%;
                top: 0%;
                position: absolute;
            }
            ul li:hover ul.name
            {
                display: block;
            }
            ul li ul.name li{
                display: block;
            }

        </style>
    </head>
    <body>
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Programming</a>
            <ul class="name">
              <li><a href="#">C</a>
                <ul class="topic">
                    <li><a href="#">Tutorial</a></li>
                    <li><a href="#">Program</a></li>
                    <li><a href="#">Interview Q/A</a></li>
                </ul>
            </li>
              <li><a href="#">C++</a>
                <ul class="topic">
                    <li><a href="#">Tutorial</a></li>
                    <li><a href="#">Program</a></li>
                    <li><a href="#">Interview Q/A</a></li>
                </ul>
            </li>
              <li><a href="#">Java</a>
                <ul class="topic">
                    <li><a href="#">Tutorial</a></li>
                    <li><a href="#">Program</a></li>
                    <li><a href="#">Interview Q/A</a></li>
                </ul>
            </li>
              <li><a href="#">Python</a>
                <ul class="topic">
                    <li><a href="#">Tutorial</a></li>
                    <li><a href="#">Program</a></li>
                    <li><a href="#">Interview Q/A</a></li>
                </ul>
            </li>
            </ul>
            </li>
            <li><a href="#">Projects</a></li>
            <li><a href="#">Registration</a></li>
            <li><a href="#">Login</a></li>
            <li><a href="#">About</a></li>
        </ul>
    </body>
</html>

Now save this file with name submenu.html inside the created folder [Submenu]. Note:Don't forget to type .html after the file name because .html is the extension for HTML file.

Step 3:Download and store image: First click here to download image. After downloading the image rename it with bg.jpg and then store image into the folder Submenu.

After doing these your created folder will look like below.

Display Submenu On Mouse Hover in HTML and CSS

Step 4:Run HTML file: Now its time to run HTML file so right click on submenu.html file and then select open with and then select chrome browser or you can select any browser for output. 

Display Submenu On Mouse Hover in HTML and CSS


You will get output screen like below screenshot.

Display Submenu On Mouse Hover in HTML and CSS


Now when you will move mouse on menu then submenu will open automatically and when you mouse out then submenu will hide automatically. For better experience see the below screenshot.

Display Submenu On Mouse Hover in HTML and CSS

I hope now you can  create "Display Submenu On Mouse Hover in HTML and CSS". If you have any doubt regarding this post  or you want something more in this post then let me know by comment below i will work on it definitely.
 

Request:-If you found this post helpful then let me know by your comment and share it with your friend. 
 
If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other. 

If you like my post then share it with your friends. Thanks­čśŐHappy Coding.

Post a Comment

0 Comments