纯css制作导航菜单下拉

/ 0评 / 0

效果:

html代码:

<ul id="menu">
<li><a href="#">测试</a></li>
<li> <a href="#">测试下拉</a>
<ul>
<li><a href="#">下拉1</a> </li>
<li><a href="#">下拉2</a> </li>
<li><a href="#">下拉3</a> </li>
</ul>
</li>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
</ul>

css代码:

ul{
    list-style: none;
    padding: 0;
}
#menu a{
    text-decoration: none;
    width: 150px;
    padding: 14px 0;
    text-align: center;
    float: left;
    color: #f1f2f3;
}
#menu li:hover{
    background-color: #00a7d0;
}
#menu ul a{
    width: 150px;
    border: none;
    display: block;
}
#menu ul a:hover{
    background-color: #00a7d0;
    color: white;
}
#menu >li{
    float: left;
    border:1px solid #363b3f;
    background-color: #363b3f;
    position: relative;
}
#menu ul{
    margin: 20px 0 0 0;
    visibility: hidden;
    position: absolute;
    background-color: #363b3f;
    top:44px;
    padding: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,.12);
    transition: all .2s ease-in-out;
}
#menu li:hover>ul{
    opacity:1 ;
    visibility: visible;
    margin: 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *