簡體   English   中英

asp.NET - 菜單上選定頁面的靜態選定樣式的問題

[英]asp.NET - Problems with Static Selected Style for a Selected Page on the menu

我正在使用帶有C#的asp.NET 4.0,並且最近為我的本地Web應用程序創建了一個自定義設計。 我希望當選擇一個頁面時,它有不同的背景顏色(通常在普通的html + css中我們只是將菜單項設置為活動狀態)。 我嘗試過使用但它不起作用,它與其他顏色保持相同的顏色。 有沒有人有這方面的經驗?

Site Master中的代碼:

            <h2>Dashboard</h2>
            <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Vertical" >
                <StaticSelectedStyle CssClass="selectedMenu" /> 
                <Items>
                    <asp:MenuItem NavigateUrl="~/Default.aspx" Text="View Submissions"/>
                    <asp:MenuItem NavigateUrl="~/Imports.aspx" Text="Import"/>
                    <asp:MenuItem NavigateUrl="~/Submission.aspx" Text="Insert Submission"/>
                    <asp:MenuItem NavigateUrl="~/Reports.aspx" Text="Reports"/>
                    <asp:MenuItem NavigateUrl="~/CurrencyMaintenance.aspx" Text="Currency Maintenance" />
                    <asp:MenuItem NavigateUrl="~/Remittance.aspx" Text="Remittance" />
                </Items>
            </asp:Menu>

CSS:

/* TAB MENU   
----------------------------------------------------------*/
div.hideSkiplink
{
    background-color:#3a4f63;
    width:100%;
}

div.menu
{
    padding: 4px 0px 4px 8px;
}

div.menu ul
{
    list-style: none;
    margin: 0px;
    padding: 0px;
    width: auto;
}

div.menu ul li a, div.menu ul li a:visited
{
    background-color: #FFF; /*680840*/
    border: 1px #4e667d solid;
    height: 20px;
    width: 175px;
    color: #000; /*FFF*/
    display: block;
    line-height: 1.35em;
    padding: 4px 20px;
    text-decoration: none;
    white-space: nowrap;
}

div.menu ul li a:hover
{
    background-color: #680840;
    color: #FFF;
    text-decoration: none;
}

.selectedMenu
{
    background-color: #680840 !important;
    color: #FFF !important;
    text-decoration: none !important;
}

div.menu ul li a:active
{
    background-color: #680840;
    color: #cfdbe6;
    text-decoration: none;
}

這就是它在Hover上的樣子,我想對選中的效果類似。

菜單

這似乎是.NET菜單的一個錯誤。 這里有一些關於此的信息 你可能想要做的是刪除staticSelectedStyle屬性,然后將其添加到你的css:

.menu a.static.selected
{
    background-color: #680840 !important;
    color: #FFF !important;
    text-decoration: none !important;
}

您可能還需要在主頁的頁面加載中添加一些代碼,以確定哪個應該是所選項目,如下所示:

protected void Page_Load(object sender, EventArgs e)
{
    string path = Request.AppRelativeCurrentExecutionFilePath;
    foreach (MenuItem item in NavigationMenu.Items)
    {
        item.Selected = item.NavigateUrl.Equals(path, StringComparison.InvariantCultureIgnoreCase);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM