需要帮助制作在悬停时打开的子菜单

时间:2013-04-08 20:57:37

标签: html css menu hover submenu

我有一个我已经构建的菜单,目前工作正常,我正在尝试添加当鼠标悬停在菜单项上时出现的子菜单项。有谁知道如何做到这一点?

<div id="menu">
            <a  href="#" >Home</a>
            <a  href="#">Submit New Record</a>
            <a   href="#">Sales by Salesperson</a>
            <a   href="#">Total Sales</a>
            <a  href="#" >Sales by Issue</a>
            <a  href="#" >Sales by Ad Size</a> 
            <a  href="#" >Add New User</a>  
            <a href="#">Edit Record</a> 
            <a href="#">Logout</a>
            </div></center>
<style>
#menu{
background-color:#3F9AD1;
height:75px;
width:1206px;
}

#menu a{
border-style:solid;
border-width:2px;
border-color:white;
padding-top: 20px;
float:left;
display:block;
width:130px;
height:70px;
text-decoration:none;
color:white;
text-align:center;
font-family: Arial;
/*box-shadow: 0 -7px 22px 6px #000000 inset;*/
}

#menu a:hover{
    color:#3F9AD1;
    background-color:white;

#html { 
height: 100%; 
margin-bottom: 0.01em;
overflow-y: scroll;
}

</style>

2 个答案:

答案 0 :(得分:3)

我通常这样做:

<ul class="menu">
    <li>Main Menu Item
        <ul class="submenu">
            <li>Sub Menu Item</li>
        </ul>
    </li>
</ul>

然后css就像这样:

ul.submenu {
    display: none;
}

li:hover ul.submenu {
    display: block;
}

答案 1 :(得分:1)

您可以到这里学习使用他们的示例教程。这很容易。只是处理你悬停状态。

http://line25.com/tutorials/how-to-create-a-pure-css-dropdown-menu