【发布时间】:2012-03-12 18:27:12
【问题描述】:
我在 MVC 3 项目中使用 HTML5 和 CSS3,但我的导航栏出现问题。
这就是我的导航栏:
当用户将鼠标悬停在链接上时,会出现粉红色的子菜单。而且这一切都是用 CSS3 完成的,根本没有 javascript。
我想要做的是,当有人访问我的 web 应用程序“HEM”,即“HOME”时,应该像图片一样自动选择它。当用户导航到让我们说“ADMIN”时,粉红色的子菜单总是在那里。
我怎样才能做到这一点?
这是我的 CSS:
ul#nav {
position:relative;
float: left;
width: 961px;
margin: 0;
padding: 0;
list-style: none;
/* gradient */
background: url(../../Content/img/nav-tile.gif) repeat-x;
}
ul#nav li {
display: inline;
}
ul#nav li a {
float: right;
font: bold 12px verdana,arial,tahoma,sans-serif;
line-height: 40px;
color: #fff;
text-decoration: none;
margin: auto;
padding: 0 35px;
}
/* APPLIES THE ACTIVE STATE */
ul#nav .current a, ul#nav li:hover > a {
color: #fff;
text-decoration: none;
text-shadow: 1px 1px 1px #330000;
background: #dd006b;
}
/* THE SUBMENU LIST HIDDEN BY DEFAULT */
ul#nav ul {
display: none;
}
/* WHEN THE FIRST LEVEL MENU ITEM IS HOVERED, THE CHILD MENU APPEARS */
ul#nav li:hover > ul {
position: absolute;
display: block;
width: 961px;
height: 30px;
position: absolute;
margin: 40px 0 0 0;
/* gradient */
background: #dd006b url(../img/menu-child.png) repeat-x;
background: -webkit-gradient(linear, left top, left bottom, from(#dd006b), to(#a1014e));
background: -moz-linear-gradient(top, #dd006b, #a1014e);
background: linear-gradient(-90deg, #dd006b, #a1014e);
}
ul#nav li:hover > ul li a {
float: left;
font: bold 12px verdana,arial,tahoma,sans-serif;
line-height: 30px;
color: #fff;
text-decoration: none;
margin: 0;
padding: 2 30px 0 0;
background: #dd006b url(../img/menu-child.png) repeat-x;
background: -webkit-gradient(linear, left top, left bottom, from(#dd006b), to(#a1014e));
background: -moz-linear-gradient(top, #dd006b, #a1014e);
background: linear-gradient(-90deg, #dd006b, #a1014e);
}
ul#nav li:hover > ul li a:hover {
text-decoration: none;
text-shadow: none;
}
我在 MVC 中为“HEM”又名“HOME”的布局如下:
<li>@Html.ActionLink("HEM","Index","Home")
<ul></ul>
</li>
提前致谢!
【问题讨论】:
-
如果是动态构建的,不就是把.current类加到li里面吗?
标签: javascript html css asp.net-mvc-3