Solved

How do i change the background color of my [sub] menu items?

Posted on 2014-03-31
5
605 Views
Last Modified: 2015-03-10
How do I place ID names or class (or CssClass) names within my menu and sub menu items to change the background colors? I'm open to any method (including inline) that will allow me to change the background color. I'm including my HTML code. [ASP .NET 3.5]

<asp:Menu ID="DropDownMenu" runat="server" Orientation="Horizontal" CssClass="SubDropDownMenu">
                            <DynamicHoverStyle BackColor="Green" />
                            <Items>
                                <asp:MenuItem Text="Home" Value="Item1"/>
                                <asp:MenuItem Text="About Us" Value="Item2" NavigateUrl="~/AboutUs.aspx">
                                    <asp:MenuItem Text="Mission" Value="Sub Item1" NavigateUrl="~/Mission.aspx"></asp:MenuItem>
                                    <asp:MenuItem Text="History" Value="Sub Item2"></asp:MenuItem>
                                    <asp:MenuItem Text="Staff" Value="Sub Item3"></asp:MenuItem>
                                    <asp:MenuItem Text="Accomplishments" Value="Sub Item4"></asp:MenuItem>
                                </asp:MenuItem>
                                <asp:MenuItem Text="Classes Info" Value="Item2">
                                    <asp:MenuItem Text="Tiny tot" Value="Sub Item1"></asp:MenuItem>
                                    <asp:MenuItem Text="Pre School" Value="Sub Item2"></asp:MenuItem>
                                    <asp:MenuItem Text="Beginner" Value="Sub Item3"></asp:MenuItem>
                                    <asp:MenuItem Text="Intermediate" Value="Sub Item4"></asp:MenuItem>
                                    <asp:MenuItem Text="Boys Gymnastics" Value="Sub Item5"></asp:MenuItem>
                                    <asp:MenuItem Text="Tumbling" Value="Sub Item6"></asp:MenuItem>
                                    <asp:MenuItem Text="Tuition" Value="Sub Item4"></asp:MenuItem>
                                </asp:MenuItem>
                                <asp:MenuItem Text="Clompetitive Teams" Value="Item2">
                                    <asp:MenuItem Text="USAG Compulsory" Value="Sub Item1"></asp:MenuItem>
                                    <asp:MenuItem Text="USAG Optional" Value="Sub Item2"></asp:MenuItem>
                                    <asp:MenuItem Text="Recreational" Value="Sub Item3"></asp:MenuItem>
                                    <asp:MenuItem Text="League" Value="Sub Item4"></asp:MenuItem>
                                </asp:MenuItem>
                                <asp:MenuItem Text="Activities" Value="Item2">
                                    <asp:MenuItem Text="Birthday Parties" Value="Sub Item1"></asp:MenuItem>
                                    <asp:MenuItem Text="Parents Nite Out" Value="Sub Item2"></asp:MenuItem>
                                    <asp:MenuItem Text="RecreatiOpen Gymonal" Value="Sub Item3"></asp:MenuItem>
                                    <asp:MenuItem Text="Sleepovers" Value="Sub Item4"></asp:MenuItem>
                                </asp:MenuItem>
                                <asp:MenuItem Text="Special Events" Value="Item2">
                                    <asp:MenuItem Text="K C Classic American Princess Meet" Value="Sub Item1"></asp:MenuItem>
                                    <asp:MenuItem Text="Santa Invitationa Meet/Show" Value="Sub Item2"></asp:MenuItem>
                                    <asp:MenuItem Text="Field Trips" Value="Sub Item3"></asp:MenuItem>
                                    <asp:MenuItem Text="Daycares" Value="Sub Item4"></asp:MenuItem>
                                    <asp:MenuItem Text="Camps" Value="Sub Item5"></asp:MenuItem>
                                </asp:MenuItem>
                                <asp:MenuItem Text="Links" Value="Item2">
                                    <asp:MenuItem Text="USA Gymnastics" Value="Sub Item1"></asp:MenuItem>
                                    <asp:MenuItem Text="MO USAG" Value="Sub Item2"></asp:MenuItem>
                                </asp:MenuItem>
                                <asp:MenuItem Text="Contact Us" Value="Item2" NavigateUrl="~/kcgymnastics.com/ContactUs.aspx">
                                </asp:MenuItem>
                            </Items>
                        </asp:Menu>

Open in new window

0
Comment
Question by:mikesExpertExchange
  • 3
  • 2
5 Comments
 
LVL 26

Expert Comment

by:Alan Warren
Comment Utility
Hi mikesExpertExchange

Try adding a style block in the head section of the page
  <style type="text/css">
    #DropDownMenu ul ul li {
      background-color:red;
    }
  </style>

Open in new window

Respectfully yours,
Alan
0
 
LVL 1

Author Comment

by:mikesExpertExchange
Comment Utility
I've tried:

    <style type="text/css">
        #DropDownMenu ul ul li,
        .SubDropDownMenu ul ul li,
        .ctl00_DropDownMenu_0 ul ul li,
        #ctl00_DropDownMenu ul ul li
        {
            background-color: #930790;
        }
    </style>

but none of these seem to work. what am i doing wrong?
0
 
LVL 26

Accepted Solution

by:
Alan Warren earned 500 total points
Comment Utility
Hi mikesExpertExchange,
this is probably a better example which you could adapt to suit
<%@ Page Language="VB" %>

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <style type="text/css">
    .level1
    {
        color: white;
        background-color: black;
        font-variant: small-caps;
        font-size: large;
        font-weight: bold;
        padding: 0 8px;
    }

    .level1:hover
    {
        background-color: yellow;
    }

    .level2
    {
        color: blue;
        font-family: Gill Sans MT !important;
        font-size: medium;
        background-color:gray;
        padding-left:12px;
    }
    .level2:hover
    {
        background-color:green;
    }


    .level3
    {
        color: black;
        background-color: silver;
        font-family: Gill Sans MT !important;
        font-size: small;
        padding: 0 4px;
    }
    .level3:hover
    {
        background-color: orange;
    }

    .level4
    {
        background-color: gray !important;
        color: White !important;
        font-size: small;
        padding: 0 4px;
    }   
    .level4:hover
    {
        background-color: violet;
    }

  </style>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:Menu ID="DropDownMenu" runat="server" Orientation="Horizontal"  >
        <LevelMenuItemStyles>
            <asp:MenuItemStyle CssClass="level1"/>
            <asp:MenuItemStyle CssClass="level2"/>
            <asp:MenuItemStyle CssClass="level3" />
            <asp:MenuItemStyle CssClass="level4" />
          </LevelMenuItemStyles>
        <Items>
            <asp:MenuItem Text="Home" Value="Item1"/>
            <asp:MenuItem Text="About Us" Value="Item2" NavigateUrl="~/AboutUs.aspx">
                <asp:MenuItem Text="Mission" Value="Sub Item1" NavigateUrl="~/Mission.aspx"></asp:MenuItem>
                <asp:MenuItem Text="History" Value="Sub Item2"></asp:MenuItem>
                <asp:MenuItem Text="Staff" Value="Sub Item3"></asp:MenuItem>
                <asp:MenuItem Text="Accomplishments" Value="Sub Item4"></asp:MenuItem>
            </asp:MenuItem>
            <asp:MenuItem Text="Classes Info" Value="Item2">
                <asp:MenuItem Text="Tiny tot" Value="Sub Item1"></asp:MenuItem>
                <asp:MenuItem Text="Pre School" Value="Sub Item2"></asp:MenuItem>
                <asp:MenuItem Text="Beginner" Value="Sub Item3"></asp:MenuItem>
                <asp:MenuItem Text="Intermediate" Value="Sub Item4"></asp:MenuItem>
                <asp:MenuItem Text="Boys Gymnastics" Value="Sub Item5"></asp:MenuItem>
                <asp:MenuItem Text="Tumbling" Value="Sub Item6"></asp:MenuItem>
                <asp:MenuItem Text="Tuition" Value="Sub Item4"></asp:MenuItem>
            </asp:MenuItem>
            <asp:MenuItem Text="Clompetitive Teams" Value="Item2">
                <asp:MenuItem Text="USAG Compulsory" Value="Sub Item1"></asp:MenuItem>
                <asp:MenuItem Text="USAG Optional" Value="Sub Item2"></asp:MenuItem>
                <asp:MenuItem Text="Recreational" Value="Sub Item3"></asp:MenuItem>
                <asp:MenuItem Text="League" Value="Sub Item4"></asp:MenuItem>
            </asp:MenuItem>
            <asp:MenuItem Text="Activities" Value="Item2">
                <asp:MenuItem Text="Birthday Parties" Value="Sub Item1"></asp:MenuItem>
                <asp:MenuItem Text="Parents Nite Out" Value="Sub Item2"></asp:MenuItem>
                <asp:MenuItem Text="RecreatiOpen Gymonal" Value="Sub Item3"></asp:MenuItem>
                <asp:MenuItem Text="Sleepovers" Value="Sub Item4"></asp:MenuItem>
            </asp:MenuItem>
            <asp:MenuItem Text="Special Events" Value="Item2">
                <asp:MenuItem Text="K C Classic American Princess Meet" Value="Sub Item1"></asp:MenuItem>
                <asp:MenuItem Text="Santa Invitationa Meet/Show" Value="Sub Item2"></asp:MenuItem>
                <asp:MenuItem Text="Field Trips" Value="Sub Item3"></asp:MenuItem>
                <asp:MenuItem Text="Daycares" Value="Sub Item4"></asp:MenuItem>
                <asp:MenuItem Text="Camps" Value="Sub Item5"></asp:MenuItem>
            </asp:MenuItem>
            <asp:MenuItem Text="Links" Value="Item2">
                <asp:MenuItem Text="USA Gymnastics" Value="Sub Item1"></asp:MenuItem>
                <asp:MenuItem Text="MO USAG" Value="Sub Item2"></asp:MenuItem>
            </asp:MenuItem>
            <asp:MenuItem Text="Contact Us" Value="Item2" NavigateUrl="~/kcgymnastics.com/ContactUs.aspx">
            </asp:MenuItem>
        </Items>
      </asp:Menu>     
    </div>
    </form>
</body>
</html>

Open in new window

Respectfully yours,
Alan
0
 
LVL 1

Author Comment

by:mikesExpertExchange
Comment Utility
@Alan: This is something that I can work with so thank you. Last question, I haven't worked with HTML much in the last couple of years so I'm a bit confused, as to why there seems to be "extra" <td> elements in the HTML of my menu (in fire fox firebug). They are creating space[more space than I want] between the horizontal items in my main menu (level 1) . I don't see them in the raw HTML that i wrote to create the menu so i'm just a bit confused as to where they are coming from. I'm including pics to help explain.

extra <td> tag 1
extra <tag> 2
                        <asp:Menu ID="DropDownMenu" runat="server" Orientation="Horizontal">
                            <%--<DynamicHoverStyle BackColor="Green" />--%>
                            <LevelMenuItemStyles>
                                <asp:MenuItemStyle CssClass="level1" />
                                <asp:MenuItemStyle CssClass="level2" />
                                <asp:MenuItemStyle CssClass="level3" />
                                <asp:MenuItemStyle CssClass="level4" />
                            </LevelMenuItemStyles>
                            <Items>
                                <asp:MenuItem Text="Home" Value="Item1" />
                                <asp:MenuItem Text="About Us" Value="Item2" NavigateUrl="~/AboutUs.aspx">
                                    <asp:MenuItem Text="Mission" Value="Sub Item1" NavigateUrl="~/Mission.aspx"></asp:MenuItem>
                                    <asp:MenuItem Text="History" Value="Sub Item2"></asp:MenuItem>
                                    <asp:MenuItem Text="Staff" Value="Sub Item3"></asp:MenuItem>
                                    <asp:MenuItem Text="Accomplishments" Value="Sub Item4"></asp:MenuItem>
                                </asp:MenuItem>
                            </Items>
                        </asp:Menu>

Open in new window

0
 
LVL 1

Author Closing Comment

by:mikesExpertExchange
Comment Utility
Thank you.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now