下拉式导航栏

学着这个网站的样子,做了个下拉式的导航栏。使用javascript,如果你禁用了javascript,就不能正常工作了。我在firefox,ie,msn下都看了,挺正常的。如果你发现这个导航栏不能正常工作,请告诉我,在评论里留下你使用的系统和浏览器。

我简单介绍一下制作方法。

1。html 代码,例子:

<ul id=”navsite”>

<li><a href=”index.php” style=”width: 4em;” >首页</a>
</li>

<li><a href=”archives.php” style=”width: 4em;” >档案</a>
<ul id=”category”>
<li><a href=”index.php?cat=3″>科技</a></li>
<li><a href=”index.php?cat=2″>网络</a></li>
</ul>
</li>

</ul>

根据你的实际需要更改。

2、css code 例子:

ul#navsite,
#navsite ul {
font: 1em Verdana, sans-serif;
padding: 0;
margin: 0;
list-style: none;
background-color: white;
float: right;
}
#navsite li {
float: left; /* arrange top menu items horizontally */
text-align: center;
}
/* Absolute position with auto setting means the item will appear
where it would have appeared normally, but is taken out of the
flow and floats above all the content. */
#navsite li ul {
position: absolute;
top: auto;

left: -999em; /* for better accessibility than using display:none */
}
* > html #navsite li ul { /* “Tan Hack” for IE Mac only */
display: none;
left: auto;
}
#navsite li:hover ul,
* html #navsite li.sfhover ul { /* for IE-Win and other non-IE browsers */
left: auto;
}
* > html #navsite li.sfhover ul { /* “Tan Hack” for IE Mac only */
display: block; /* IE-Mac gets confused by the left:-999em rule, so we do this. */
border: 1px solid #778; /* to visually confirm this rule is being used on IE-Mac */
}
#navsite li ul li {
float: none; /* sub-menu items will stack vertically as normal list */
text-align: left;
}
#navsite a {
display: block;
text-decoration: none;
color: #FFF;
background-color: #73a0c5;
padding: 1px 0px 2px 0px; /* no right-left padding for top level items */
border: 1px solid #FFF;
}
#navsite li ul li a { /* for sub-menu items */
/* Apply the width here (not to li) so that IE regards entire width as clickable */
/* This also seems to fix the “3px gap between list items” bug in IE. */
width: 6em;
border-top-style: none; /* to get single line between items */
padding: 1px 10px 2px 10px;
}
/* note: important to keep ordering of LVHA link, visited, hover, active */
#navsite a:link:hover,
#navsite a:visited:hover {
color: #73a0c5;
background-color: #FFF;
border-color: #FFF;
}

根据你的设计需要进行更改。

3、javascript 代码

<script type=”text/javascript” language=”JavaScript”>
<!–
sfHover = function() {
var sfEls = document.getElementById(”navsite”).getElementsByTagName(”LI”);
for (var i=0; i sfEls[i].onmouseover=function() {
this.className+=" sfhover";

}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
else { //IE 5.2 Mac does not support attachEvent
var old = window.onload;
window.onload = function() { if (old) old(); sfHover(); }
}
//-->
</script>

加进网页的header里。

做了这三步就可以了。

11 Responses to “下拉式导航栏”

  1. asiapan 说:

    做得真精致,羡慕ing

  2. forclear 说:

    收藏了,等放假也改成下拉式.

  3. 下拉式导航栏的做法

    桑葚写了个下拉式导航栏的代码放了出来。虽然我并不欣赏这类导航栏的风格,但世事难料,没准哪天突然心情变了呢。记之以备用。

    1。html 代码,例子:

    <ul id=”navsite”>

    <li&gt…

  4. [...] 尝试了N个模板的修改,用wordpress index builder自定义创建再修改, 甚至自己写。都走到一半就丢弃了。都是一些琐碎到自己都觉得不好意思的问题。对自己的能力深表怀疑。最后还是用了joe(一个几天换一次模板的theme痴)的theme1,一个很漂亮齐全的theme。且构造相似,所以才有了今天。sidebar用的是桑葚的技术,这个东西我现在还在一知半解中,不过的确做得很周到。以及海豚的wordpress theme系列教程,如果不是看了这个我对wp模板的认识恐怕还停留在原始阶段,对大段的php没有任何概念。当然这个东西绝对不是他所描述“搭积木”那么简单,可是至少有了可以自己做主的信心,也是第一步。还有风言疯语里面的那些链接。无力的时候也想到上次与隐藏人物说叫他帮忙设计,好不容易开了口,他也没时间…… [...]

  5. neuben 说:

    不错!很有用.

  6. andy 说:

    我没有子菜单的显示

  7. MEDiCi 说:

    抱歉,还是有些问题
    下拉菜单弄上去了.
    但是css没能整成自己所愿的.
    如果想把菜单放在page的右边的话,是否是更改
    #navsite li {
    float: left; /* arrange top menu items horizontally */
    text-align: center;
    }
    这里面的?
    为何我更改无效?
    另外
    科技
    这个指向链接是不是类别里面的?
    不知道为何我也没链成功.

  8. MEDiCi 说:

    ie 6.0 不能使用.

  9. Lawrence 说:

    IE7里面经常会出现菜单弹出后不能收回的情况,这样整个页面上有时就会出现三四个菜单同时弹出。我正在测试用的页面:http://fenado.blogbus.com/

  10. 万俟小刀 说:

    这个不能自动缩回去吗? 我这里出来后就不能回缩了

Leave a Reply