Reputation: 551
I have a navbar which displays a list of image links. I want to change the image based on hover and selection. This is my result:
html:
<li>
<a href='' id='home' />
</li>
css:
nav li {
display: inline-block;
width: 128px;
height: 128px;
}
nav li a #home {
background-image: url('../images/home.png');
}
nav li a:hover #home {
background-image: url('../images/home-hover.png');
}
nav li a:selected #home {
background-image: url('../images/home-selected.png');
}
Why isn't this working correctly?
Upvotes: 0
Views: 209
Reputation: 2895
Your css is looking for a child with id #home. It should be nav li a#home:hover{}
etc.
You'll also need to set either block or inline-block as well as width/height on the a tag.
Example: http://jsfiddle.net/6HmLP/1/
Upvotes: 3
Reputation: 488
You need to close your a
tag and include content: <a href='' id='home' />some text</a>
You should also display your a
as a block or inline-block and give it a width and height so your background image can actually display as intended.
Also, your selectors are wrong. By saying a #home
, you're looking for "any element with an id of home
, which is a descendent element of a
". Which doesn't exist in your HTML. Instead, you can target it with a#home
which means "the a
element that has an id of home
".
Upvotes: 0
Reputation: 462
You need to address it like this:
nav li a#home { ... }
nav li a#home:hover { ... }
Upvotes: 0