Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
below is my html code. how to add sub menu using css to this code
HTML
<div id="menu" class="container">
        <nav>
			<ul>
				<li class="current_page_item"><a href="#">Homepage</a></li>
				<li><a href="#">Manage internship</a>
             <ul>
				   <li><a href="#">Photoshop</a></li>
				   <li><a href="#">Illustrator</a></li>
				   <li><a href="#">Web Design</a></li>
			</ul>
                </li>
              

				<li><a href="#">Blog</a></li>
				<li><a href="#">Portfolio</a></li>
				<li><a href="#">Contact</a></li>
                <li><a href="#">Logout</a></li>
                <li><a href="../../Log_in.aspx">Login</a></li>

			</ul>
            </nav>
		</div>
Posted
Comments
Sergey Alexandrovich Kryukov 26-Mar-14 2:39am    
Do you mean "show sub-menu on hover"? If you added a sub-menu on each hover event, you would have way too many sub-menus. :-)
And what? Even without Javascript?
—SA
jayraj86 26-Mar-14 2:51am    
YES "show sub-menu on hover". i want the same using CSS
Sergey Alexandrovich Kryukov 26-Mar-14 3:20am    
Sure. Thank you.
—SA

1 solution

Thank you for your clarifications in the comments to the question. You could find a pure CSS solution if you just thought about it. The neat trick is the combination of the pseudo-class selector hover with the adjacent sibling selector ('+'). Suppose, for simplicity, you need to show/hide some div on hover. The idea is explained in the top answer to this question: http://stackoverflow.com/questions/5210033/show-div-on-hover-with-only-css[^].

Now, you need to show/hide not div, but something else, say, ul element of certain class. Let's say, you have the classes names "menu" and "submenu", then you need to combine the idea shown above with your HTML and that class. It could look something like:

CSS
ul.submenu {
    display: none;
}

il.menu:hover + ul.submenu {
    display: block;
}


Again, this is only the development of the same idea, but this should be enough for you to develop HTTP+CSS working together the way you want.

Further reading:
Suckerfish Dropdowns: http://alistapart.com/article/dropdowns[^],
The Adjacent-Sibling Selector: http://meyerweb.com/eric/articles/webrev/200007a.html[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900