I am trying to add a pseudo hover to a <a>
tag, but no image is showing with either css class. Please can you tell me what I am doing wrong as I am new to css.
#AIM a {
left:420px;
top:590px;
position: absolute;
background-image: url('http://maxk.me/img/aim.png');
}
#AIM a:hover {
left:420px;
top:590px;
position: absolute;
background-image: url('http://maxk.me/img/aim-hover.png');
}
<a id="AIM" href="http://dribbble.com/_max" />
You <a>
has no width or height so there is nowhere for a background image to display.
#AIM a
is a selector for anchor tags inside an element with id #AIM
like in this example: http://jsfiddle.net/Paulpro/5yg7t/ . You want to select an anchor tag with id="AIM"
in which case you should just use an ID selector since ID's are unique. Use this:
#AIM {
left:420px;
top:590px;
position: absolute;
width: 55px;
height: 54px;
background-image: url('http://maxk.me/img/aim.png');
}
#AIM:hover {
background-image: url('http://maxk.me/img/aim-hover.png');
}
#AIM a
matches <a>
tags inside of #AIM
.
You need to write a#AIM
to match <a>
tags that are #AIM
.
You can also just write #AIM
, since IDs must be unique.
Your <a>
tags have no content, so they'll be effectively 0x0 invisible elements. Either add some text:
<a ...> </a>
or give them a size in the CSS:
a#AIM {
height: 10px;
width: 10px;
}
or better yet, both.
Change the css to the following
a#AIM {
left:420px;
top:590px;
position: absolute;
background-image: url('http://maxk.me/img/aim.png');
}
a#AIM:hover {
left:420px;
top:590px;
position: absolute;
background-image: url('http://maxk.me/img/aim-hover.png');
}
Change the HTML to the following
<a id="AIM" href="http://dribbble.com/_max" />
Try adding
display: block;
to both classes; then try specifying a width and height...
width: 20px;
height: 20px;
The A tag has no idea how big your image is. A is also an inline element, so it stretches to the size of its content (usually the text inside).
You need to:
Make it a block element
{ display: block; width:300px; height:300px; left:420px; top:590px; position: absolute; background-image: url('http://maxk.me/img/aim.png'); }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.