Div <li> menu color not updating properly in ASP.NET master page c#

Gani_tpt 2,106 Reputation points
2024-05-18T13:29:33.9266667+00:00

I am using menu control using <ul> and <li> tag.

I am trying to apply some different color while menu selected.

But, applying color not reflected in menu. (particularly white color for text in the menu)

what will be the problem in the below code.

if (activepage.Contains("Customer.aspx"))
            {
                menuCustomer.Attributes.Add("class", "MenuList");
                menuHome.Attributes.CssStyle.Add("background-color", "#819542");
                menuHome.Attributes.CssStyle.Add("color", "white");
            }

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,386 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,535 questions
{count} votes

Accepted answer
  1. Lan Huang-MSFT 28,126 Reputation points Microsoft Vendor
    2024-05-20T05:49:29.9766667+00:00

    Hi @Gani_tpt,

    First, the code you provided is inconsistent with capitalization.

    User's image

    If you need to change the color for text, you need to set the css of the <a> tag, not <li>.

    For example:

    <div id="homemenu-wrapper">
         <div id="homemenu" class="container">
             <ul>
                 <li id="MenuHome" runat="server"><a href="Home.aspx" id="AHome" runat="server">Home</a></li>
                 <li id="MenuCustomer" runat="server"><a href="ITApprover.aspx">Customer</a> </li>
                 <li id="MenuHelp" runat="server"><a href="#">Help</a></li>
             </ul>
         </div>
     </div>
    
     AHome.Attributes.CssStyle.Add("background-color", "#819542");
     AHome.Attributes.CssStyle.Add("color", "white");
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful