1

HTML

<ul id="NavList">
    <li id="Home"><a href="Second.aspx"></a></li>
    <li id="About"><a href="Second.aspx"></a></li>
</ul>

CSS:

#Home {
    background: url('NavIcons/1.gif');
}
#Home a:hover {
    background: url('NavIcons\2.gif');
}

I am creating a navigation list that changes its image on hover, but it doesnt work.

Zword
  • 6,605
  • 3
  • 27
  • 52
Stella
  • 7
  • 5

4 Answers4

0

try like this

#Home {
    background:  url(NavIcons/1.gif) 0 0 no-repeat;
}

#Home:hover {
    background:  url(NavIcons/2.gif) 0 0 no-repeat;
}

JsFiddle demo : But this for changing color on hover

Please check for image URL if not coming properly

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
0

a tag will probably not be large enough to show your image. You can try this

#Home {
    background: url('NavIcons/1.gif');
}
#Home:hover {
    background: url('NavIcons/2.gif');
}

or give width and height to a.

Kuzgun
  • 4,649
  • 4
  • 34
  • 48
0

I think you might want to try styling the A rather then the LI since it's just a placeholder as list item for the actual link.

#Home a {
    background: url('NavIcons/1.gif');
}
#Home a:hover {
    background: url('NavIcons/2.gif');
}
Remy Lagerweij
  • 177
  • 2
  • 7
0

If you want to show the background change of #Home or #About when hovering only on a then you can use the following:

HTML

<ul id="NavList">
    <li id="Home"><a href="Second.aspx">1</a><div></div></li>
    <li id="About"><a href="Second.aspx">2</a><div></div></li>
</ul>

CSS

#Home,#About {
    position:relative;
    width:70px;
    height:50px;
}
#Home div, #About div{
    position:absolute;
    background: url('https://i.stack.imgur.com/2JzQz.jpg');
    background-position:-20px 0px;
    top:0px;
    width:100%;
    height:100%;
}
#Home a,#About a{
    position:absolute;
    top:20px;
    left:20px;
    z-index:100;
}
#Home a:hover+div , #About a:hover+div{
    background: url('https://i.stack.imgur.com/7rx8G.jpg');
    background-position:-20px 0px;
}

Demo


Got this idea from How to style the parent element when hovering a child element? .My CSS is different but using same idea.

Community
  • 1
  • 1
Zword
  • 6,605
  • 3
  • 27
  • 52