首页 > 开发 > CSS > 正文

没有JS只用CSS制作的网页下拉菜单

2024-07-11 08:22:36
字体:
来源:转载
供稿:网友

这款下拉菜单栏的实现非常简单,没有用到复杂的js代码,完全依靠css代码来实现的,只需进行简单的修改变换就可以了,以下是代码实例:

html代码:

<div id="nav">
    <ul>
    <li class="menu2" onmouseover="this.classname='menu1'" onmouseout="this.classname='menu2'">home page    
    <div class="list">
        <a href="http://www.VeVb.com/">网页设计</a><br />
        <a href="#">我的首页</a><br _fcksavedurl=""#">我的首页</a><br" />
        <a href="#">我的日志</a><br />
        <a href="#">我的日志</a><br />
        <a href="#">我的相册</a><br />
        <a href="#">我的收藏</a><br />
    </div>
    </li>
    <li class="menu2" onmouseover="this.classname='menu1'" onmouseout="this.classname='menu2'">connection 
    <div class="list">
        <a href="http://www.VeVb.com/">网页设计</a><br />
        <a href="#">我的首页</a><br _fcksavedurl=""#">我的首页</a><br" />
        <a href="#">我的日志</a><br />
        <a href="#">我的相册</a><br />
        <a href="#">我的收藏</a><br />
    </div>
    </li>
    <li class="menu2" onmouseover="this.classname='menu1'" onmouseout="this.classname='menu2'">my files    
    <div class="list">
        <a href="http://www.VeVb.com/">网页设计</a><br />
        <a href="#">我的相册</a><br _fcksavedurl=""#">我的相册</a><br" />
        <a href="#">我的收藏</a><br />
    </div>
    </li>
    <li class="menu2" onmouseover="this.classname='menu1'" onmouseout="this.classname='menu2'">management    
    <div class="list">
        <a href="http://www.VeVb.com/">网页设计</a><br />
        <a href="#">我的首页</a><br _fcksavedurl=""#">我的首页</a><br" />
        <a href="#">我的日志</a><br />
        <a href="#">我的相册</a><br />
        <a href="#">我的收藏</a><br />
        <a href="#">我的日志</a><br />
        <a href="#">我的相册</a><br />
        <a href="#">我的收藏</a><br />
    </div>
    </li>
    </ul>
</div>

下面是css代码:

body{
    background-color:white;
    font-size:12px;
    font-family:arial, helvetica, sans-serif;
    margin:0px;
    padding:0px;
    color:white;
}
ul,li{
    margin:0px;
    padding:0px;
}
li{
    display:inline;
    list-style:none;
    list-style-position:outside;
    text-align:center;
    font-weight:bold;
    float:left;
}
a:link{
    color:#336601;
    text-decoration:none;
    float:left;
    width:100px;
    padding:3px 5px 0px 5px;
}
a:visited{
    color:#336601;
    text-decoration:none;
    float:left;
    padding:3px 5px 0px 5px;
    width:100px;
}
a:hover{
    color:white;
    float:left;
    padding:3px 3px 0px 20px;
    width:88px;
    text-decoration:none;
    background-color:#539d26;
}
a:active{
    color:white;
    float:left;
    padding:3px 3px 0px 20px;
    width:88px;
    text-decoration:none;
    background-color:#bd06b4;
}
#nav{
    width:600px;
    height:30px;
    border-bottom:0px;
    padding:0px 5px;
    position:absolute;
    z-index:1;
    left: 198px;
    top: 25px;
}
.list{
    line-height:20px;
    text-align:left;
    padding:4px;
    font-weight:normal;
}
.menu1{
    width:120px;
    height:auto;
    margin:6px 4px 0px 0px;
    border:1px solid #9cdd75;
    background-color:#f1fbec;
    color:#336601;
    padding:6px 0px 0px 0px;
    cursor:hand;
    overflow-y:hidden;
    filter:alpha(opacity=70);
    -moz-opacity:0.7;
}
.menu2{
    width:120px;
    height:18px;
    margin:6px 4px 0px 0px;
    background-color:#f5f5f5;
    color:#999999;
    border:1px solid #eee8dd;
    padding:6px 0px 0px 0px;
    overflow-y:hidden;
    cursor:hand;
}

具体演示:


[ctrl+a 全部选择 提示:你可先修改部分代码,再按运行]

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表