[英]ASP.NET highlight selected MenuItem
I am trying to highlight selected MenuItem in my navigation panel, but can't seem to understand why it's not working. 我试图在我的导航面板中突出显示选定的MenuItem,但似乎无法理解为什么它不起作用。
Here is the ASPX file: 这是ASPX文件:
<asp:Menu ID="Main_menu" runat="server" Orientation="Horizontal">
<StaticSelectedStyle CssClass="nav_selected" />
<StaticItemTemplate>
<div class="nav_style">
<asp:Label runat="server" Text='<%# Eval("Text") %>' />
</div>
</StaticItemTemplate>
<Items>
<asp:MenuItem NavigateUrl="~/home.aspx" Text="home" />
<asp:MenuItem NavigateUrl="~/what-it-can-do.aspx" Text="what it can do" />
<asp:MenuItem NavigateUrl="#" Text="pricing" />
<asp:MenuItem NavigateUrl="#" Text="news & events" />
<asp:MenuItem NavigateUrl="#" Text="partner with us" />
</Items>
</asp:Menu>
Here is the CSS file: 这是CSS文件:
.nav_selected
{
background-color:red;
}
.nav_style
{
list-style:none;
background-color:#242C32;
border-radius:3px;
color:#F5F5F5;
border-top:4px solid #242C32;
border-bottom:4px solid #242C32;
border-left:12px solid #242C32;
border-right:12px solid #242C32;
font:14px calibri;
}
.nav_style:hover
{
color:#0B8BBF;
}
EDIT
编辑
HTML that is rendered(hope this is the right one): 呈现的HTML(希望这是正确的):
<a href="#PageHeader_Main_menu_SkipLink"><img alt="Skip Navigation Links" src="/WebResource.axd?d=ILNNewtPvesYj-keR2OtzG1BUzU1n0CHnwnTQ2TLfIDO2cZBagUxjpSkZw3gSRJ6NvONia8D7dYw2ebl0erF93Ds_kQ1&t=635201010537823876" width="0" height="0" style="border-width:0px;" /></a><div id="PageHeader_Main_menu">
<ul class="level1">
<li><a class="level1 selected" href="home.aspx">
<div class="nav_style">
<span>home</span>
</div>
</a></li><li><a class="level1" href="what-it-can-do.aspx">
<div class="nav_style">
<span>what it can do</span>
</div>
</a></li><li><a class="level1" href="#">
<div class="nav_style">
<span>pricing</span>
</div>
</a></li><li><a class="level1" href="#">
<div class="nav_style">
<span>news & events</span>
</div>
</a></li><li><a class="level1" href="#">
<div class="nav_style">
<span>partner with us</span>
</div>
</a></li>
</ul>
</div><a id="PageHeader_Main_menu_SkipLink"></a>
Have a look at the fiddle I have created for you. 看看我为你创造的小提琴 。
Otherwise, could not really find the specific problem with your code. 否则,无法真正找到您的代码的具体问题。
.nav_style
{
list-style:none;
font:14px calibri;
background-color: none;
padding: 10px;
}
.nav_style:hover
{
background-color:red;
}
.selected .nav_style{
background-color: yellow;
}
As you see I have used .selected .nav_style to highlight the selected tab. 如您所见,我已使用.selected .nav_style突出显示所选标签。 Give that a shot.
试一试。
Oh.. and I haven't touched your markup. 哦..我没有触及你的标记。 So, the styles should work.
所以,风格应该有效。
Your class is "selected", but your style is "nav_selected" 您的课程已“选中”,但您的风格为“nav_selected”
<a class="level1 selected" href="home.aspx">
vs VS
.nav_selected
{
background-color:red;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.