代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Css
】
CSS+JS实现兼容性很好的无限级下拉菜单
作者:
Dezai.CN
/ 发布于
2012/4/1
/
618
在IE8下测试没问题,其他没测,请测试后决定是否使用
<div><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"></div> <div><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"></div> <div><head></div> <div><title>CSS+JS实现兼容性很好的无限级下拉菜单</title></div> <div><style type="text/css"></div> <div>*{ margin:0; padding:0; border:0;} <div>body{font:12px/130% verdana,geneva,arial,helvetica,sans-serif,宋体;}li{list-style:none;} <div>.clearfix:after{content:" ";display:block;height:0;clear:both;visibility:hidden;}.clearfix{display:inline-block;} <div>a:link{ color:#000; text-decoration:none; } <div>a:visited{ color:#000; text-decoration:none; } <div>a:hover{ color:#000; text-decoration:none; } <div>.menu{ width:778px; height:26px; background:#fff; margin:0 auto;} <div>.menusel{ float:left;width:100px; position:relative; height:25px; background:#ddd; line-height: 25px; margin-left: 1px; *margin-left: 0px;_margin-left: -1px;} <div>.menusel h2{ font-size:12px; } <div>.menusel a{ display: block;text-align:center; width:100px;border:1px solid #a4a4a4; height:25px; border-bottom:1px solid #a4a4a4; position:relative; z-index:2;} <div>.menusel a:hover{ border:1px solid #a4a4a4; border-bottom:1px dashed #eeeeee; position:relative; z-index:2; height:25px;} <div>.ahover a{border-bottom:1px dashed #eeeeee; background:#eeeeee; } <div>.position{ position:absolute; z-index:1;} <div>.menusel ul{width:125px; background:#eee; border:1px solid #a4a4a4; margin-top: -1px; position:relative; z-index:1; display:none;} <div>.menusel .block{ display:block;} <div>.typeul li{border-bottom:1px dashed #a4a4a4;width:125px; position:relative; float:left; } <div>.typeul li a{ border:none;width:125px; } <div>.typeul li a:hover{ border:none; background:#ddd;} <div>.typeul{ margin-left:0; } <div>.typeul ul{left:125px; top:0; position:absolute;} <div>.fli{ margin-left: -1px; border-left:#eeeeee solid 1px;} <div>.menusel .lli{ border:none; } <div></style></div> <div><script type="text/javascript">document.execCommand("BackgroundImageCache", false, true);</script><!-- IE6背景图片闪烁问题 --></div> <div></head></div> <div><body></div> <div><div class="menu"></div> <div><div id="menu1" class="menusel"></div> <div> <h2><a href="/">菜单1</a></h2></div> <div> <div class="position"></div> <div> <ul class="clearfix typeul"></div> <div> <li><a href="http://www.33567.cn">菜单选项1-2</a></li></div> <div> <li></div> <div> <a href="#">菜单选项1-2</a></div> <div> <ul></div> <div> <li class="fli"><a href="#">菜单选项1-2-1</a></li></div> <div> <li class="lli"><a href="#">菜单选项1-2-2</a></li></div> <div> </ul></div> <div> </li></div> <div> <li><a href="http://www.7caidy.com">菜单选项1-2</a></li></div> <div> <li class="lli"><a href="#">菜单选项1-2</a></li></div> <div> </ul></div> <div> </div><!-- position --></div> <div> </div><!-- menusel --></div> <div> <div id="menu2" class="menusel"></div> <div> <h2><a href="#">菜单2</a></h2></div> <div> <div class="position"></div> <div> <ul class="clearfix typeul"></div> <div> <li><a href="#">菜单选项2-2</a></li></div> <div> <li><a href="#">菜单选项2-2</a></div> <div> <ul></div> <div> <li class="fli"><a href="#">菜单选项2-2-1</a></li></div> <div> <li class="lli"><a href="#">菜单选项2-2-2</a></div> <div> <ul></div> <div> <li class="fli"><a href="#">菜单选项2-2-1</a></li></div> <div> <li class="lli"><a href="#">菜单选项2-2-2</a></div> <div> </li></div> <div> </ul></div> <div> </li></div> <div> </ul></div> <div> </li></div> <div> <li><a href="#">菜单选项2-2</a></li></div> <div> <li class="lli"><a href="#">菜单选项2-2</a></li></div> <div> </ul></div> <div> </div><!-- position --></div> <div> </div><!-- menusel --></div> <div> <div id="menu3" class="menusel"></div> <div> <h2><a href="#">菜单3</a></h2></div> <div> <div class="position"></div> <div> <ul class="clearfix typeul"></div> <div> <li><a href="#">菜单选项3-2</a></li></div> <div> <li><a href="#">菜单选项3-2</a></div> <div> <ul></div> <div> <li class="fli"><a href="#">菜单选项3-2-1</a></li></div> <div> <li class="lli"><a href="#">菜单选项3-2-2</a></div> <div> <ul></div> <div> <li class="fli"><a href="#">菜单选项3-2-1</a></li></div> <div> <li class="lli"><a href="#">菜单选项3-2-2</a></div> <div> <ul></div> <div> <li class="fli"><a href="#">菜单选项3-2-1</a></li></div> <div> <li class="lli"><a href="#">菜单选项3-2-2</a></li></div> <div> </ul></div> <div> </li></div> <div> </ul></div> <div> </li></div> <div> </ul></div> <div> </li></div> <div> <li><a href="#">菜单选项3-2</a></li></div> <div> <li class="lli"><a href="#">菜单选项3-2</a></li></div> <div> </ul></div> <div> </div><!-- position --></div> <div></div><!-- menusel --></div> <div></div><!-- menu --></div> <div><script type="text/javascript"></div> <div>for(var x = 1; x < 4; x++)</div> <div>{</div> <div>var menuid = document.getElementById("menu"+x);</div> <div>menuid.num = x;</div> <div>type();</div> <div>} <div>function type()</div> <div>{</div> <div>var menuh2 = menuid.getElementsByTagName("h2");</div> <div>var menuul = menuid.getElementsByTagName("ul");</div> <div>var menuli = menuul[0].getElementsByTagName("li");</div> <div>menuh2[0].onmouseover = show;</div> <div>menuh2[0].onmouseout = unshow;</div> <div>menuul[0].onmouseover = show;</div> <div>menuul[0].onmouseout = unshow;</div> <div>function show()</div> <div>{</div> <div>menuul[0].className = "clearfix typeul block"</div> <div>} <div>function unshow()</div> <div>{</div> <div>menuul[0].className = "typeul"</div> <div>} <div>for(var i = 0; i < menuli.length; i++)</div> <div> {</div> <div> menuli[i].num = i;</div> <div> var liul = menuli[i].getElementsByTagName("ul")[0];</div> <div> if(liul)</div> <div> {</div> <div> typeshow()</div> <div> } <div> } <div>function typeshow()</div> <div>{</div> <div>menuli[i].onmouseover = showul;</div> <div>menuli[i].onmouseout = unshowul;</div> <div>} <div>function showul()</div> <div>{</div> <div>menuli[this.num].getElementsByTagName("ul")[0].className = "block";</div> <div>} <div>function unshowul()</div> <div>{</div> <div>menuli[this.num].getElementsByTagName("ul")[0].className = "";</div> <div>} <div>} <div></script></div> <div></body></div> <div></html></div> <div></div>
试试其它关键字
无限级下拉菜单
同语言下
.
前端PC-移动端CSS公共样式+HTML
.
手机端页面通用样式
.
H5页面通用头部设置
.
elect默认样式美化代码兼容移动端和pc端
.
按钮效果 css
.
唤醒app
.
放大效果
.
html5+css3实现上拉和下拉刷新
.
html上传图片后,在页面显示上传的图片
.
html5实现点击弹出图片
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3