Reputation: 801
I'm trying to add a sub menu using css. When I hover my mouse over the a link "Top Menu", I want a sub menu to appear. See the code at here
<div id="navbar"> <span class="navbutton">
<a id="button-1" href="#">Shop</a>
</span>
<span class="navbutton">
<a href="#">
Test1</a>
</span>
<span class="navbutton"><a id="button-3" href="#">Top Menu</a>
</span>
<span class="navbutton"><a id="button-4" href="#">Test1</a>
</span>
<a class="linefreak"></a><a class="linefreak"></a>
<span class="navbutton"><a id="button-5" href="#">Test2</a>
</span>
</div>
Any help is much appreciated. Thanks
Upvotes: 1
Views: 66
Reputation: 547
SW4 is right.. and for your example here the fiddle:
.navbutton:hover #button-3+.submenu{
display:inline;
}
.submenu{
display:none;
}
Upvotes: 0
Reputation: 71140
The below should get you started- note you're likely better off using lists (ul
, li
) for this type of setup.
HTML
<ul>
<li>Shop</li>
<li>Test1</li>
<li>Top Menu
<ul>
<li>Sub Item</li>
<li>Sub Item</li>
<li>Sub Item</li>
<li>Sub Item</li>
<li>Sub Item</li>
</ul>
</li>
<li>Test1</li>
<li>Test2</li>
</ul>
CSS
ul {
list-style:none;
background:green;
}
ul, li {
margin:0;
padding:0;
}
li {
display:inline-block;
padding:10px 10px;
}
ul li ul {
display:none;
position:absolute;
}
ul li ul li {
display:block;
}
ul li:hover ul {
display:block;
}
Upvotes: 2