Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-03-31
5
Medium Priority
?
875 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:Michael Sterling
  • 3
  • 2
5 Comments
 
LVL 26

Expert Comment

by:Alan Warren
ID: 39968426
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:Michael Sterling
ID: 39968460
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 2000 total points
ID: 39968477
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:Michael Sterling
ID: 39971200
@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:Michael Sterling
ID: 40657111
Thank you.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

885 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