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

BeUnique 2,332 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");
            }

Developer technologies | ASP.NET | Other
Developer technologies | C#
{count} votes

Accepted answer
  1. Lan Huang-MSFT 30,191 Reputation points Microsoft External Staff
    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.