views:

55

answers:

6

I have a transparent PNG that partially overlaps a button. The buttons becomes inactive where the image overlaps. Is there a way to turn the transparency "off" so the button is clickable behind it? Or are there any other tricks that might fix this problem?

A: 

give the button a higher z-index maybe?

Mar_Garina
No, I want the image to be above the button. I just don't want the image to interfere with the button clickable area
jwerre
you should probably clarify that in your question, it's unclear when first reading it.
brad
A: 

Give the button a higher z-index to make it come above the transparent image

document.getElementById('buttonId').style.zIndex = -5
Tom Gullen
I don't want the button above the image
jwerre
+3  A: 

The img transparency has nothing to do with whether or not you can click the button, so 'turning the transparency off' is not going to do anything for you.

As Mar_Garina points out, z-index is what determines which element lies above/below other elements. If you want that button to always be on top, give it a higher z-index. Note however that this image will the be overlapped by that button which may not be what you want.

Also check out button sliding doors with css if you're looking for some custom button styling

brad
just trying to help... your negativity is unnecessary, it didn't appear that you really understood how html elements' z-index works so I explained... Sliding doors mentioned as it seems you have a styling issue. No, there's no way the section of an element covered by another with higher z-index will be clickable
brad
A: 

Although I wouldn't recommend it, you could create an anchor with the following style:

<a href="#" class="className">&nbsp;</a>

a.className {
  display: block;
  width: [width of button];
  height: [height of button];
  z-index: [above image];
}

To mimic the button action....

Khan
A: 

Couldn't you do this instead:

<style type="text/css">
#button
{
background-image: url("[image location]");
width: [image width];
width: [image height];
}
</style>

And

<input type="button" value="button" id="button"/>

This makes the button clickable and makes the image ontop.

Chief17
A: 

I would say that in general, there is indeed no solution to the problem. An image area is always rectangular, no matter whether its pixels are transparent or not.

However, @Chief17's answer gave me an idea that might work if your button is not using the OS's rendering style, and doesn't have a background image itself.

If that is the case, and the general layout situation permits it, you could set the image that should overlap the button as that button's background image - in addition to the image floating around on the page. Using background-position, you would then have to adjust the image's position so that it almost leaves the visible area of the button, covering only the small overlapping area that the button should not cover.

Is that understandably put? It's using the button's background-image property to fake overlapping while in truth, the overlapping area is the background image of the button.

This works only when you have really tight control over the button's position and other factors. It may not work out for you.

Pekka