【问题标题】:Asp.menu - staying hover effect when activeAsp.menu - 活动时保持悬停效果
【发布时间】:2014-10-23 12:01:06
【问题描述】:

我有一个母版页,其中有 asp.net 菜单控件。

我想要的是,如果我单击菜单中的链接,我希望我刚刚单击的菜单项在其处于活动状态时保持悬停效果。

有没有可能使用 asp.net 菜单? :)

我尝试过使用我在网上找到的代码:

<div class="topnav">
    <asp:menu id="topnav" runat="server" orientation="Horizontal" renderingmode="List" skiplinktext="" maximumdynamicdisplaylevels="1" viewstatemode="Enabled" >
        <items>
            <asp:menuitem navigateurl="~/Default.aspx" text="Home" value="home"></asp:menuitem>
            <asp:menuitem navigateurl="~/Overview.aspx" text="Overview" value="overview"></asp:menuitem>
            <asp:menuitem navigateurl="~/Benefits.aspx" text="Benefits" value="benefits"></asp:menuitem>
            <asp:menuitem navigateurl="~/Home.aspx" text="Hardware" value="hardware"></asp:menuitem>
            <asp:menuitem navigateurl="~/SDK.aspx" text="Develop" value="SDK"></asp:menuitem>
        </items>
    </asp:menu>
</div>

.topnav
{
    background-color: #ddd;
    /*margin-top: 1px;*/
    line-height: 22px;
    float: right;
    margin-right: 11px;
    background: url(../img/shadow.gif) repeat-y top right;


    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: bold;
    color: #777;
    text-align: center;
}

.topnav #topnav li
{
    float: left;
}

.right .topnavcont
{
    width: 767px;
    background-color: #dddddd !important;
    height: 22px;
}

.topnav li
{
    width: 109px;
}

.topnav a:link, .topnav a:visited
{
    color: #777;
    display: block;
    background-image: url(../img/bg_n-s.gif);
    background-repeat: repeat-x;
    text-decoration: none;
    visibility: visible;
}

.topnav  a:hover 
{
    color: #fff !important;
    background-image: url(../img/bg_h-s.gif);
    display: block;
    visibility: visible;
}

topnav .staticmenuitemselected
{
    color: red;
    display: block;
    background-image: url(../img/bg_n-s.gif);
    background-repeat: repeat-x;
    text-decoration: none;
    visibility: visible;
}

【问题讨论】:

  • 不,我从他那里拿了代码 :) 只是为了测试它,但我无法像他解释的那样让它工作 :) + 我不认为我们有同样的问题,但因为我已经玩了一个星期了,我只是拿他的代码来测试它是否可能:)

标签: asp.net menu hover master-pages


【解决方案1】:

遍历menuItem并检查当前页面URL是否包含NavigateUrl

      foreach (MenuItem item in mn.Items)
      {
     if   (Request.Url.AbsoluteUri.ToLower().Contains(Page.ResolveUrl(item.NavigateUrl.ToLower()))
     {
       item.Selected = true;
      }
        }

    REFER THIS [http://stackoverflow.com/questions/8053337/asp-net-4-highlight-menu-item-for-current-page]

_______ 或 ___________

您的菜单中有一个 StaticSelectedStyle 属性。

      <asp:menu id="menu" runat="server" >
      <staticselectedstyle backcolor=""
      borderstyle=""
      bordercolor=""
      borderwidth=""/>
      </menu> 
      FIND MORE [http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menu.includestyleblock.aspx] and [http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menu.staticselectedstyle.aspx]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-16
    • 1970-01-01
    • 2018-03-16
    • 1970-01-01
    • 1970-01-01
    • 2013-08-28
    相关资源
    最近更新 更多