views:

22

answers:

1

Hello,

I have a menu made up of images and on a:hover I want to add a background image rather than simply doing image replacements (all in CSS, no JavaScript).

However, if I simply change the background image, while transparency and horizontal alignment are fine, it's just at the wrong vertical placement. No matter what I try the background image goes to the very bottom of the image and you see about a text height of background image below the main menu image.

Any ideas on how to fix this?

In it's simplest form it can be repeated as follows:

<html>
<head>
<style>a:hover{background:url('over.png');}</style>
 </head>
<body>
    <a href="#"><img src="item.png" style="border:0; " /></a>
</body>
</html>

item.png is showing about 10 pixels of the top of its image at the bottom of over.png Thanks.

Adding background-position: x y; still only shows the over.png at the bottom of the image and crops it to the height of one character.

Below shows the two images and what comes out on the right image of what happens

A: 

It'd be easier to debug if you gave us a screenshot and some code. But it sounds like you might just need to position the background image within the element using background-position. You can use pixels, percentages or just top,bottom,left,right to place a background image wherever you want it within an element. http://www.w3schools.com/css/pr_background-position.asp. You might also want to look into image sprites for rollover effects. You would place the original and rollover images onto one file and simple change the background-position on hover.

Justin Lucas
as far as I could see when I looked before background-position is only for horizontal having left, right, center options only, plus a pixel offset from the left? It is vertical alignment that is wrong.
neil
Sorry, I'll rephrase that. I tried that, it didn't seem to work. It still locks the background image to the bottom of the main image. Changing background-position simply adjusts the offset of what is shown at the bottom. If that makes sense?
neil