编写纯 CSS 弹出菜单的原理及实现 By shawl.qiu

编写纯 CSS 弹出菜单的原理及实现 By shawl.qiu
摘要: 
本文介绍了使用 CSS 编写适用于 Opera, Firefox, IE 的多风格弹出菜单

说明:
编写 CSS 弹出菜单的要点不外乎当鼠标移到目标上时, 显示出隐藏的标签. 
要隐藏的标签使用 display:none; 属性进行隐藏. 
触发显示隐藏标签主要使用 :hover 属性, 并用 display:block; 显示隐藏的标签.

但由于浏览器对 CSS 的支持并非一致.
对于 Opera 或者 Firefox, 我们可以编写出纯 CSS 菜单, 他们支持任何标签的 :hover 属性.
而对于 IE 浏览器, :hover 只对 a 标签起作用, 但我们可以使用脚本的 onmouseover, onmouseout 模拟出其他标签的 :hover 属性.
因此编写适用于 IE 的 CSS 弹出菜单必须使用到少许的脚本.

目录:
1. 编写直排右侧弹出的 CSS 菜单. 
1.1 真正的基于 Opera, Firefox 纯 CSS 弹出菜单
1.2 兼容 IE, Opera, Firefox 的 CSS 弹出菜单(脚本实现)

2. 编写横排底部弹出的 CSS 菜单. 
2.1 真正的基于 Opera, Firefox 纯 CSS 弹出菜单
2.2 兼容 IE, Opera, Firefox 的 CSS 弹出菜单(脚本实现)

3. 结论

4. 预览

shawl.qiu
2006-10-01


1. 编写直排右侧弹出的 CSS 菜单. 

1.1 真正的基于 Opera, Firefox 纯 CSS 弹出菜单
linenum <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " "> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> <style type="text/css"> /*<![CDATA[*/ /* shawl.qiu pure css popup menu demo */     body{ margin:0px auto; width:768px; /* 定义页面居中显示,*/}     *{text-decoration:none!important; /* 定义所有链接不显示下划线 */}     .pmVerticalRightOut{background-color:#fff!important; /* 定义主菜单域背景色 */}      .pmVerticalRightOut .level{  /* 定义一级类别属性 */         width:120px; /* 宽度 */         height:17; /* 高度 */         position:relative; /* 显示位置为相对位置 */         display:block; /* 以块模式显示 */         background-color:#D8D8D8; /* 背景色 */         padding:0px 2px; /* 文字内补丁间隔 */         margin:0px 0px 1px 0px; /* 菜单外补丁间隔 */     }     .pmVerticalRightOut .level:hover { /* 当鼠标划过一级菜单时 */         background-color:#6633FF; /* 背景色 */         color:#FFFFFF; /* 文字颜色 */     }     .pmVerticalRightOut .level_{display:none; /* 默认隐藏二级类别 */}          .pmVerticalRightOut .level:hover .level_ { /* 鼠标划过时触发显示二级类别 */         display:block; /* 以块显示 */         left:124px; /* 相对于一级类别显示的位置 */         width:120px; /* 宽度 */         height:auto; /* 高度 */         top:0px; /* 相对于一级类别所在位置的顶端 */         background-color:#EFEFEF; /* 定义背景色 */         position:absolute; /* 位置为绝对位置 */     }     .pmVerticalRightOut .level:hover .level_ .level_title {         /* 定义二级类别标题样式 */         font-weight:bold; /* 字体加粗 */         background-color:#A7ADFE; /* 背景色 */         color:white; /* 文字颜色 */     }     .pmVerticalRightOut .level:hover .level_ a:hover {         /* 定义二级类别链接显示样式 */         background-color:#F83658; /* 背景色 */         color:white; /* 文字颜色 */     }     .pmVerticalRightOut .level_ * {          /* 定义所有二级类别通用属性 */         display:block; /* 以块显示 */         color:black; /* 文字颜色 */         padding:0px 2px; /* 内补丁间隔 */     } /*]]>*/ </style> </head> <body> <p/><p/><p/><p/><p/> <div class="pmVerticalRightOut" id="pmVerticalRightOut">     <div class="level">         <div class="levelTitle">level</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level&id=1">level_ title 1</a>             <a href="?cat=level&id=2">level_ title 2</a>             <a href="?cat=level&id=3">level_ title 3</a>             <a href="?cat=level&id=4">level_ title 4</a>             <a href="?cat=level&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 1</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_1&id=1">level_ title 1</a>             <a href="?cat=level_1&id=2">level_ title 2</a>             <a href="?cat=level_1&id=3">level_ title 3</a>             <a href="?cat=level_1&id=4">level_ title 4</a>             <a href="?cat=level_1&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 2</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_2&id=1">level_ title 1</a>             <a href="?cat=level_2&id=2">level_ title 2</a>             <a href="?cat=level_2&id=3">level_ title 3</a>             <a href="?cat=level_2&id=4">level_ title 4</a>             <a href="?cat=level_2&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 3</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_3&id=1">level_ title 1</a>             <a href="?cat=level_3&id=2">level_ title 2</a>             <a href="?cat=level_3&id=3">level_ title 3</a>             <a href="?cat=level_3&id=4">level_ title 4</a>             <a href="?cat=level_3&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 4</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_4&id=1">level_ title 1</a>             <a href="?cat=level_4&id=2">level_ title 2</a>             <a href="?cat=level_4&id=3">level_ title 3</a>             <a href="?cat=level_4&id=4">level_ title 4</a>             <a href="?cat=level_4&id=5">level_ title 5</a>         </div>     </div> </div> </body> </html>
1.2 兼容 IE, Opera, Firefox 的 CSS 弹出菜单(脚本实现)
linenum <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " "> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> <style type="text/css"> /*<![CDATA[*/ /* shawl.qiu pure css popup menu demo */     body{ margin:0px auto; width:768px; /* 定义页面居中显示,*/}     *{text-decoration:none!important; /* 定义所有链接不显示下划线 */}     /* ------------------- start 针对 Opera, Firefox 的 CSS 弹出菜单 -------------------*/     .pmVerticalRightOut{background-color:#fff!important; /* 定义主菜单域背景色 */}      .pmVerticalRightOut .level{  /* 定义一级类别属性 */         width:120px; /* 宽度 */         height:17; /* 高度 */         position:relative; /* 显示位置为相对位置 */         display:block; /* 以块模式显示 */         background-color:#D8D8D8; /* 背景色 */         padding:0px 2px; /* 文字内补丁间隔 */         margin:0px 0px 1px 0px; /* 菜单外补丁间隔 */     }     .pmVerticalRightOut .level:hover { /* 当鼠标划过一级菜单时 */         background-color:#6633FF; /* 背景色 */         color:#FFFFFF; /* 文字颜色 */     }     .pmVerticalRightOut .level_{display:none; /* 默认隐藏二级类别 */}          .pmVerticalRightOut .level:hover .level_ { /* 鼠标划过时触发显示二级类别 */         display:block; /* 以块显示 */         left:124px; /* 相对于一级类别显示的位置 */         width:120px; /* 宽度 */         height:auto; /* 高度 */         top:0px; /* 相对于一级类别所在位置的顶端 */         background-color:#EFEFEF; /* 定义背景色 */         position:absolute; /* 位置为绝对位置 */     }     .pmVerticalRightOut .level:hover .level_ .level_title {         /* 定义二级类别标题样式 */         font-weight:bold; /* 字体加粗 */         background-color:#A7ADFE; /* 背景色 */         color:white; /* 文字颜色 */     }     .pmVerticalRightOut .level:hover .level_ a:hover {         /* 定义二级类别链接显示样式 */         background-color:#F83658; /* 背景色 */         color:white; /* 文字颜色 */     }     .pmVerticalRightOut .level:hover .level_ * {          /* 定义所有二级类别通用属性 */         display:block; /* 以块显示 */         color:black; /* 文字颜色 */         padding:0px 2px; /* 内补丁间隔 */     }     /* ------------------- end 针对 Opera, Firefox 的 CSS 弹出菜单 -------------------*/          /* ------------------- start 针对 IE 的 CSS 弹出菜单 -------------------*/     .levelIe{  /* 定义一级类别属性 */         width:120px; /* 宽度 */         height:17; /* 高度 */         position:relative; /* 显示位置为相对位置 */         display:block; /* 以块模式显示 */         background-color:#D8D8D8; /* 背景色 */         padding:0px 2px; /* 文字内补丁间隔 */         margin:0px 0px 1px 0px; /* 菜单外补丁间隔 */     }     .levelIe .level_ { /* 鼠标划过时触发显示二级类别 */         display:block; /* 以块显示 */         left:124px; /* 相对于一级类别显示的位置 */         width:120px; /* 宽度 */         height:auto; /* 高度 */         top:0px; /* 相对于一级类别所在位置的顶端 */         background-color:#EFEFEF; /* 定义背景色 */         position:absolute; /* 位置为绝对位置 */     }     .levelIe .level_ .level_title {         /* 定义二级类别标题样式 */         font-weight:bold; /* 字体加粗 */         background-color:#A7ADFE; /* 背景色 */         color:white; /* 文字颜色 */     }     .levelIe .level_ a:hover {         /* 定义二级类别链接显示样式 */         background-color:#F83658; /* 背景色 */         color:white; /* 文字颜色 */     }     .levelIe .level_ * {          /* 定义所有二级类别通用属性 */         display:block; /* 以块显示 */         color:black; /* 文字颜色 */         padding:0px 2px; /* 内补丁间隔 */     }     /* ------------------- end 针对 IE 的 CSS 弹出菜单 -------------------*/ /*]]>*/ </style> <script type="text/javascript"> //<![CDATA[ if (navigator.appName=="Microsoft Internet Explorer") {     function fPmVerticalRightOut() {         var getItem = document.getElementById("pmVerticalRightOut").getElementsByTagName("div");         for (var i=0; i<getItem.length; i++) {             getItem[i].onmouseover=function() {                  if(    this.className=="level"){                     this.className="levelIe";                 }             }             getItem[i].onmouseout=function() {                  if(    this.className=="levelIe"){                     this.className="level";                 }             }//css popup menu script by shawl.qiu         }     }     window.onload=fPmVerticalRightOut; } //]]> </script> </head> <body> <p/><p/><p/><p/><p/> <div class="pmVerticalRightOut" id="pmVerticalRightOut">     <div class="level">         <div class="levelTitle">level</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level&id=1">level_ title 1</a>             <a href="?cat=level&id=2">level_ title 2</a>             <a href="?cat=level&id=3">level_ title 3</a>             <a href="?cat=level&id=4">level_ title 4</a>             <a href="?cat=level&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 1</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_1&id=1">level_ title 1</a>             <a href="?cat=level_1&id=2">level_ title 2</a>             <a href="?cat=level_1&id=3">level_ title 3</a>             <a href="?cat=level_1&id=4">level_ title 4</a>             <a href="?cat=level_1&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 2</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_2&id=1">level_ title 1</a>             <a href="?cat=level_2&id=2">level_ title 2</a>             <a href="?cat=level_2&id=3">level_ title 3</a>             <a href="?cat=level_2&id=4">level_ title 4</a>             <a href="?cat=level_2&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 3</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_3&id=1">level_ title 1</a>             <a href="?cat=level_3&id=2">level_ title 2</a>             <a href="?cat=level_3&id=3">level_ title 3</a>             <a href="?cat=level_3&id=4">level_ title 4</a>             <a href="?cat=level_3&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 4</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_4&id=1">level_ title 1</a>             <a href="?cat=level_4&id=2">level_ title 2</a>             <a href="?cat=level_4&id=3">level_ title 3</a>             <a href="?cat=level_4&id=4">level_ title 4</a>             <a href="?cat=level_4&id=5">level_ title 5</a>         </div>     </div> </div> </body> </html>
2. 编写横排底部弹出的 CSS 菜单. 

2.1 真正的基于 Opera, Firefox 纯 CSS 弹出菜单
linenum <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " "> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> <style type="text/css"> /*<![CDATA[*/ /* shawl.qiu pure css popup menu demo */     body{ margin:0px auto; width:768px; /* 定义页面居中显示,*/}     *{text-decoration:none!important; /* 定义所有链接不显示下划线 */}     .pmHorizontalBottomOut{background-color:#fff!important; /* 定义主菜单域背景色 */}      .pmHorizontalBottomOut .level{  /* 定义一级类别属性 */         width:120px; /* 宽度 */         height:17; /* 高度 */         position:relative; /* 显示位置为相对位置 */         display:block; /* 以块模式显示 */         background-color:#D8D8D8; /* 背景色 */         padding:0px 2px; /* 文字内补丁间隔 */         margin:0px 1px 0px 0px; /* 菜单外补丁间隔 */         float:left;     }     .pmHorizontalBottomOut .level:hover { /* 当鼠标划过一级菜单时 */         background-color:#6633FF; /* 背景色 */         color:#FFFFFF; /* 文字颜色 */     }     .pmHorizontalBottomOut .level_{display:none; /* 默认隐藏二级类别 */}          .pmHorizontalBottomOut .level:hover .level_ { /* 鼠标划过时触发显示二级类别 */         display:block; /* 以块显示 */         width:124px; /* 宽度 */         height:auto; /* 高度 */         margin:0px -2px 0px -2px; /* 外补丁 */         background-color:#EFEFEF; /* 定义背景色 */         position:absolute; /* 位置为绝对位置 */     }     .pmHorizontalBottomOut .level:hover .level_ .level_title {         /* 定义二级类别标题样式 */         font-weight:bold; /* 字体加粗 */         background-color:#A7ADFE; /* 背景色 */         color:white; /* 文字颜色 */     }     .pmHorizontalBottomOut .level:hover .level_ a:hover {         /* 定义二级类别链接显示样式 */         background-color:#F83658; /* 背景色 */         color:white; /* 文字颜色 */     }     .pmHorizontalBottomOut .level_ * {          /* 定义所有二级类别通用属性 */         display:block; /* 以块显示 */         color:black; /* 文字颜色 */         padding:0px 2px; /* 内补丁间隔 */     } /*]]>*/ </style> </head> <body> <p/><p/><p/><p/><p/> <div class="pmHorizontalBottomOut" id="pmHorizontalBottomOut">     <div class="level">         <div class="levelTitle">level</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level&id=1">level_ title 1</a>             <a href="?cat=level&id=2">level_ title 2</a>             <a href="?cat=level&id=3">level_ title 3</a>             <a href="?cat=level&id=4">level_ title 4</a>             <a href="?cat=level&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 1</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_1&id=1">level_ title 1</a>             <a href="?cat=level_1&id=2">level_ title 2</a>             <a href="?cat=level_1&id=3">level_ title 3</a>             <a href="?cat=level_1&id=4">level_ title 4</a>             <a href="?cat=level_1&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 2</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_2&id=1">level_ title 1</a>             <a href="?cat=level_2&id=2">level_ title 2</a>             <a href="?cat=level_2&id=3">level_ title 3</a>             <a href="?cat=level_2&id=4">level_ title 4</a>             <a href="?cat=level_2&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 3</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_3&id=1">level_ title 1</a>             <a href="?cat=level_3&id=2">level_ title 2</a>             <a href="?cat=level_3&id=3">level_ title 3</a>             <a href="?cat=level_3&id=4">level_ title 4</a>             <a href="?cat=level_3&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 4</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_4&id=1">level_ title 1</a>             <a href="?cat=level_4&id=2">level_ title 2</a>             <a href="?cat=level_4&id=3">level_ title 3</a>             <a href="?cat=level_4&id=4">level_ title 4</a>             <a href="?cat=level_4&id=5">level_ title 5</a>         </div>     </div> </div> </body> </html>
2.2 兼容 IE, Opera, Firefox 的 CSS 弹出菜单(脚本实现)
linenum <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " "> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> <style type="text/css"> /*<![CDATA[*/ /* shawl.qiu pure css popup menu demo */     body{ margin:0px auto; width:768px; /* 定义页面居中显示,*/}     *{text-decoration:none!important; /* 定义所有链接不显示下划线 */}     /* ------------------- start 针对 Opera, Firefox 的 CSS 弹出菜单 -------------------*/     .pmHorizontalBottomOut{background-color:#fff!important; /* 定义主菜单域背景色 */}      .pmHorizontalBottomOut .level{  /* 定义一级类别属性 */         width:120px; /* 宽度 */         height:17; /* 高度 */         position:relative; /* 显示位置为相对位置 */         display:block; /* 以块模式显示 */         background-color:#D8D8D8; /* 背景色 */         padding:0px 2px; /* 文字内补丁间隔 */         margin:0px 1px 0px 0px; /* 菜单外补丁间隔 */         float:left;     }     .pmHorizontalBottomOut .level:hover { /* 当鼠标划过一级菜单时 */         background-color:#6633FF; /* 背景色 */         color:#FFFFFF; /* 文字颜色 */     }     .pmHorizontalBottomOut .level_{display:none; /* 默认隐藏二级类别 */}          .pmHorizontalBottomOut .level:hover .level_ { /* 鼠标划过时触发显示二级类别 */         display:block; /* 以块显示 */         width:124px; /* 宽度 */         height:auto; /* 高度 */         margin:0px -2px 0px -2px; /* 外补丁 */         background-color:#EFEFEF; /* 定义背景色 */         position:absolute; /* 位置为绝对位置 */     }     .pmHorizontalBottomOut .level:hover .level_ .level_title {         /* 定义二级类别标题样式 */         font-weight:bold; /* 字体加粗 */         background-color:#A7ADFE; /* 背景色 */         color:white; /* 文字颜色 */     }     .pmHorizontalBottomOut .level:hover .level_ a:hover {         /* 定义二级类别链接显示样式 */         background-color:#F83658; /* 背景色 */         color:white; /* 文字颜色 */     }     .pmHorizontalBottomOut .level_ * {          /* 定义所有二级类别通用属性 */         display:block; /* 以块显示 */         color:black; /* 文字颜色 */         padding:0px 2px; /* 内补丁间隔 */     }     /* ------------------- end 针对 Opera, Firefox 的 CSS 弹出菜单 -------------------*/          /* ------------------- start 针对 IE 的 CSS 弹出菜单 -------------------*/     .levelIe{  /* 定义一级类别属性 */         width:120px; /* 宽度 */         height:17; /* 高度 */         position:relative; /* 显示位置为相对位置 */         display:block; /* 以块模式显示 */         background-color:#D8D8D8; /* 背景色 */         padding:0px 2px; /* 文字内补丁间隔 */         margin:0px 1px 0px 0px; /* 菜单外补丁间隔 */         float:left;     }     .levelIe { /* 当鼠标划过一级菜单时 */         background-color:#6633FF; /* 背景色 */         color:#FFFFFF; /* 文字颜色 */     }     .levelIe .level_ { /* 鼠标划过时触发显示二级类别 */         display:block; /* 以块显示 */         width:124px; /* 宽度 */         height:auto; /* 高度 */         margin:0px -2px 0px -2px; /* 外补丁 */         background-color:#EFEFEF; /* 定义背景色 */         position:absolute; /* 位置为绝对位置 */     }     .levelIe .level_ .level_title {         /* 定义二级类别标题样式 */         font-weight:bold; /* 字体加粗 */         background-color:#A7ADFE; /* 背景色 */         color:white; /* 文字颜色 */     }     .levelIe .level_ a:hover {         /* 定义二级类别链接显示样式 */         background-color:#F83658; /* 背景色 */         color:white; /* 文字颜色 */     }     .levelIe .level_ * {          /* 定义所有二级类别通用属性 */         display:block; /* 以块显示 */         color:black; /* 文字颜色 */         padding:0px 2px; /* 内补丁间隔 */     }     /* ------------------- end 针对 IE 的 CSS 弹出菜单 -------------------*/ /*]]>*/ </style> <script type="text/javascript"> //<![CDATA[ if (navigator.appName=="Microsoft Internet Explorer") {     function fPmHorizontalBottomOut() {         var getItem = document.getElementById("pmHorizontalBottomOut").getElementsByTagName("div");         for (var i=0; i<getItem.length; i++) {             getItem[i].onmouseover=function() {                  if(    this.className=="level"){                     this.className="levelIe";                 }             }             getItem[i].onmouseout=function() {                  if(    this.className=="levelIe"){                     this.className="level";                 }             }//css popup menu script by shawl.qiu         }     }     window.onload=fPmHorizontalBottomOut; } //]]> </script> </head> <body> <p/><p/><p/><p/><p/> <div class="pmHorizontalBottomOut" id="pmHorizontalBottomOut">     <div class="level">         <div class="levelTitle">level</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level&id=1">level_ title 1</a>             <a href="?cat=level&id=2">level_ title 2</a>             <a href="?cat=level&id=3">level_ title 3</a>             <a href="?cat=level&id=4">level_ title 4</a>             <a href="?cat=level&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 1</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_1&id=1">level_ title 1</a>             <a href="?cat=level_1&id=2">level_ title 2</a>             <a href="?cat=level_1&id=3">level_ title 3</a>             <a href="?cat=level_1&id=4">level_ title 4</a>             <a href="?cat=level_1&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 2</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_2&id=1">level_ title 1</a>             <a href="?cat=level_2&id=2">level_ title 2</a>             <a href="?cat=level_2&id=3">level_ title 3</a>             <a href="?cat=level_2&id=4">level_ title 4</a>             <a href="?cat=level_2&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 3</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_3&id=1">level_ title 1</a>             <a href="?cat=level_3&id=2">level_ title 2</a>             <a href="?cat=level_3&id=3">level_ title 3</a>             <a href="?cat=level_3&id=4">level_ title 4</a>             <a href="?cat=level_3&id=5">level_ title 5</a>         </div>     </div>     <div class="level">         <div class="levelTitle">level 4</div>         <div class="level_">             <div class="level_title">level_ title</div>             <a href="?cat=level_4&id=1">level_ title 1</a>             <a href="?cat=level_4&id=2">level_ title 2</a>             <a href="?cat=level_4&id=3">level_ title 3</a>             <a href="?cat=level_4&id=4">level_ title 4</a>             <a href="?cat=level_4&id=5">level_ title 5</a>         </div>     </div> </div> </body> </html>

3. 结论
以上例子可以看出, 如果已经编写出一个可用的CSS弹出菜单例子, 那要编写出弹出位置在其他地方的 CSS 弹出菜单的话, 只须小小修改一下就 OK. 

4. 预览

4.1 1.2 兼容 IE, Opera, Firefox 的 CSS 弹出菜单(脚本实现) 的预览

level

level_ title

level 1

level_ title

level 2

level_ title

level 3

level_ title

level 4

level_ title

 

4.2 2.2 兼容 IE, Opera, Firefox 的 CSS 弹出菜单(脚本实现) 的预览

level

level_ title

level 1

level_ title

level 2

level_ title

level 3

level_ title

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzddwf.html