tags:

views:

22

answers:

2

Hi, I'm trying to put a user control together which will contain a menu control. what i have is a menu that is horizontally oriented, and using 4 gifs as the individual menu items with about 10px of spacing between them. So far easy enough, but what i need is to swap out each gif on hover over. im pretty sure the menu control doesn't support an image-swap-on-hover functionality, so im trying to find a work around. im guessing it will involve some clever css, but im completely stuck and simply can't figure this out. any help?

side question here: i was asked to put the menu in a user control and then register it in the master page. is there a benefit to this? why not just code the menu into the master page instead of in a separate user control?

thank you...

+1  A: 

I would suggest using two CSS styles. On your first style you could set a background image for your non-hover state. On the second style you would use a background image for your hover state. You can then use the MenuItemStyles and HoverMenuItemStyles. Here's some quick sample code:

menuItem { background-image: url('menuItemImg.gif'); background-position: left center; background-repeat: no-repeat; } hoverItem { background-image: url('hoverItemImg.gif'); background-position: left center; background-repeat: no-repeat; }

...

<asp:Menu ID="menu1" runat="server" StaticMenuItemStyle-CssClass="menuItem" StaticHoverStyle-CssClass="hoverItem">
    <Items>
      ...
    </Items>
</asp:Menu>

You may need to switch to DynamicMenuItemStyle, etc if you're using dynamic items.

Coding Gorilla
hi, i tried your sample code and it didn't work for me. since the static image and hover image are being set by css, im assuming that i don't need to set the MenuItem control's ImageUrl property, is that right, just leave it blank? when i run my code i just get a blank space where the menu should pop up. im guessing my css is wrong:.staticMenu { background-image: url('nav_home_original.gif'); background-position:left center; background-repeat:no-repeat; } .hoverMenu { background-image: url('images/nav_home_rollover.gif'); background-position:left center; background-repeat:no-repeat; }
400_the_cat
That is correct, leave the ImageUrl unset. Your CSS looks correct, but maybe you need to check the paths on your url(''). The way you have it set up it looks like that images would be in the root of the site, is that correct?Also, something I didn't show, you might need to add some margin or padding to the text to push them right past the background image; since the image is a background image, the text is allowed to sit on top of it.
Coding Gorilla
+1  A: 

What you can do is combine the method Coding Gorilla mentioned with CSS Sprites. The reason I say this is because if you just replace images the first time users hover over the menu item they will have to wait for the second image to load so it won't trantion smoothly. With the CSS Sprites Technique you load an image that contain both the non hovered and hovered states and just change the position of the image, which makes the experience more smooth.

Waleed Al-Balooshi