如何用CSS编写下拉菜单?
我编写了一个水平导航,如下所示。
但我很难尝试为其编写下拉菜单。
如果有人可以帮助我在租赁下方编写一个简单的下拉菜单(在导航栏中以海蓝色突出显示),我可以对此进行改进。
谢谢
这是我当前的 html 文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/layout.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<ul class="glossymenu">
<li class="separator"><a href="#"><b>Reservations</b></a></li>
/* Added for the drop down */
<ul class="child">
<li><a href="#"><b>New Reservation</b></a></li>
<li><a href="#"><b>Search Reservation</b></a></li>
<li><a href="#"><b>Search Customer</b></a></li>
<li><a href="#"><b>Search Vehicle</b></a></li>
</ul>
<li class="separator"><a href="#"><b>Rentals</b></a></li>
<li class="separator"><a href="#"><b>Tariffs</b></a></li>
<li class="separator"><a href="#"><b>Fleet</b></a></li>
<li class="separator"><a href="#"><b>Tools</b></a></li>
<li class="separator"><a href="#"><b>Reports</b></a></li>
<li class="separator"><a href="#"><b>System Management</b></a></li>
</ul>
</body>
这是我的 CSS 代码:
.glossymenu{
padding: 0 0 0 0px;
margin: 0 auto 0 auto;
background: url(../images/menur_bg.gif) repeat-x;
height: 36px;
list-style: none;
border:solid 1px #CCC;
}
.glossymenu li{
float:left;
}
.glossymenu li a{
float: left;
display: block;
color:#000;
text-decoration: none;
font-family: sans-serif;
font-size: 13px;
font-weight: bold;
height: 36px;
line-height: 36px;
text-align: center;
cursor: pointer;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
padding-left: 20px;
}
.glossymenu li a b{
float: left;
display:block;
padding: 0 28px 0 8px;
}
.glossymenu li a:hover{
color: #fff;
background: url(../images/menur_hover_left.gif) no-repeat;
background-position: left bottom;;
}
.glossymenu li a:hover b{
color: #fff;
background-image: url(../images/menur_hover_right.gif);
background-repeat: no-repeat;
background-position: right bottom;
}
.glossymenu li.separator {
background:url(../images/separator.gif) no-repeat;
background-position:right;
padding: 0 5px 0 3.5px;
}
/* Added for the drop down */
.glossymenu .child {
position:absolute;
visibility:hidden;
top:100px;
}
.glossymenu ul li:hover {
visibility:visible;
z-index:9999;
}
I have coded a horizontal navigation as shown below.
But I am having a hard time trying to code a drop down menu for it.
If someone can help me with coding a plain simple drop down menu below Rentals (highlight in the navigation bar in sea blue), I can improve on that.
Thanks
Here is my current html file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/layout.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<ul class="glossymenu">
<li class="separator"><a href="#"><b>Reservations</b></a></li>
/* Added for the drop down */
<ul class="child">
<li><a href="#"><b>New Reservation</b></a></li>
<li><a href="#"><b>Search Reservation</b></a></li>
<li><a href="#"><b>Search Customer</b></a></li>
<li><a href="#"><b>Search Vehicle</b></a></li>
</ul>
<li class="separator"><a href="#"><b>Rentals</b></a></li>
<li class="separator"><a href="#"><b>Tariffs</b></a></li>
<li class="separator"><a href="#"><b>Fleet</b></a></li>
<li class="separator"><a href="#"><b>Tools</b></a></li>
<li class="separator"><a href="#"><b>Reports</b></a></li>
<li class="separator"><a href="#"><b>System Management</b></a></li>
</ul>
</body>
Here is my css code:
.glossymenu{
padding: 0 0 0 0px;
margin: 0 auto 0 auto;
background: url(../images/menur_bg.gif) repeat-x;
height: 36px;
list-style: none;
border:solid 1px #CCC;
}
.glossymenu li{
float:left;
}
.glossymenu li a{
float: left;
display: block;
color:#000;
text-decoration: none;
font-family: sans-serif;
font-size: 13px;
font-weight: bold;
height: 36px;
line-height: 36px;
text-align: center;
cursor: pointer;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
padding-left: 20px;
}
.glossymenu li a b{
float: left;
display:block;
padding: 0 28px 0 8px;
}
.glossymenu li a:hover{
color: #fff;
background: url(../images/menur_hover_left.gif) no-repeat;
background-position: left bottom;;
}
.glossymenu li a:hover b{
color: #fff;
background-image: url(../images/menur_hover_right.gif);
background-repeat: no-repeat;
background-position: right bottom;
}
.glossymenu li.separator {
background:url(../images/separator.gif) no-repeat;
background-position:right;
padding: 0 5px 0 3.5px;
}
/* Added for the drop down */
.glossymenu .child {
position:absolute;
visibility:hidden;
top:100px;
}
.glossymenu ul li:hover {
visibility:visible;
z-index:9999;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你想要类似的东西吗
http://www.dynamicdrive.com/dynamicindex1/chrome/index.htm
添加:
一些基于CSS的菜单
http://purecssmenu.com/ - 我猜你可以生成 css
http://cssmenumaker.com/drop_down_css_menu.php
http://sperling.com/examples/menuh/
Do you want something like
http://www.dynamicdrive.com/dynamicindex1/chrome/index.htm
Added:
Some css based menus
http://purecssmenu.com/ -- guess you can generate the css
http://cssmenumaker.com/drop_down_css_menu.php
http://sperling.com/examples/menuh/
在您的示例中,我看不到您将鼠标悬停在第二级上的位置设置为“显示:阻止”。
这是 CSS-Dropdown-Menu 的一个简单示例。
HTML:
CSS:
in your example i can not see where you set on hover the Second-Level to "display:block".
Here is a simple example for CSS-Dropdown-Menu.
HTML:
CSS: