HTML position元素
2015-07-26 17:20
597 查看
<!doctype html> <html> <head> <meta charset="utf-8" /> <!-- <script type="text/javascript"> startList = function() { if (document.all && document.getElementById) { navRoot = document.getElementById("menu"); var allli = navRoot.getElementsByTagName("li") for (i=0; i<allli.length; i++) { node = allli[i]; node.onmouseover=function() { this.className+=" current"; } node.onmouseout=function() { this.className=this.className.replace(" current", ""); } } } } window.onload=startList; </script> --> <style type="text/css"> body { font-family: Verdana; font-size: 12px; line-height: 1.5; } /*line-height:1.5 * 12px = 18px*/ img { border-style: none; } a { color: #000; text-decoration: none; } a:hover { color: #F00; } #menu { width: 100px; border: 1px solid #CCC; border-bottom:none;} #menu ul { list-style: none; margin: 0px; padding: 0px; } #menu ul li { background: #eee; padding: 0px 8px; height: 26px; line-height: 26px; border-bottom: 1px solid #CCC; position:relative;} #menu ul li ul { display:none; position: absolute; left: 100px; top: 0px; width:100px; border:1px solid #ccc; border-bottom:none; } #menu ul li.current ul { display:block;} #menu ul li:hover ul { display:block;} </style> </head> <body> <div id="menu"> <ul> <li><a href="#">首页</a></li> <li><a href="#">网页版式布局</a> <ul> <li><a href="#">自适应宽度</a></li> <li><a href="#">固定宽度</a></li> </ul> </li> <li><a href="#">div+css教程</a> <ul> <li><a href="#">新手入门</a></li> <li><a href="#">视频教程</a></li> <li><a href="#">常见问题</a></li> </ul> </li> <li><a href="#">div+css实例</a></li> <li><a href="#">常用代码</a></li> <li><a href="#">站长杂谈</a></li> <li><a href="#">技术文档</a></li> <li><a href="#">资源下载</a></li> <li><a href="#">图片素材</a></li> </ul> </div> </body> </html> 文章出处:标准之路(http://www.aa25.cn)
效果如下:
当父元素 的 position 设为 relative 时,其子元素的 absolute position 是按照父元素的相对位置来的。如果父元素没有设置 positon:relatie,则相对body元素。
相关文章推荐
- HTMl中Meta标签详解以及meta property=og标签含义
- 001--html
- html基本标签
- 常用正则表达式大全!(例如:匹配中文、匹配html)
- HTML <map> 设置图热点
- 语义元素
- favicon.ico 的作用(收藏夹的图标文件)
- HTML<a>标签的target属性
- HTML--Note6--form
- html的文本元素总结
- HTML案例练习一
- html 标签 a target 属性
- 网页制作之html基础学习2-标签
- 网页制作之html基础学习1-简介
- html DOCTYPE声明详解
- html--html语法
- html:唤起手机qq开始对话 & 自动拨号
- 【HTML学习】新的结构化元素
- 【HTML】—常用标记
- select函数总结 www.cnblogs.com/hnrainll/archive/2011/05/05/2038186.html