Is it possible to have a image (.png) over a button and still be able to click that button
Asked
Active
Viewed 190 times
1

Radu Dragan
- 82
- 5
-
Here you have some answers. [1-Answer](http://stackoverflow.com/questions/8488005/how-to-put-a-jpg-or-png-image-into-a-button-in-html) [2-Answer](http://stackoverflow.com/questions/2920076/html-css-how-to-add-image-icon-to-input-type-button) ;-) – SvOzMaS Feb 23 '16 at 09:13
-
You should set for image `pointer-events: none;`. Just be aware of [support](http://caniuse.com/#feat=pointer-events) – A. Wolff Feb 23 '16 at 09:14
-
as you are using png image, you can use it as a background and easily you can position the button as per requirement showed in screenshot or you an use absolute position for the button too possible.. like this https://jsfiddle.net/3qxjbrL9/3/ – G.L.P Feb 23 '16 at 09:38
4 Answers
2
Using z-index
, you can indeed:
button.btn-class {
z-index: 999;
}
EDIT - You'll obviously need to ensure the image z-index
is lower that 999 as above!
Good reference: https://css-tricks.com/almanac/properties/z/z-index/

David Wilkinson
- 5,060
- 1
- 18
- 32
-
-
-
@A.Wolff Apologies I mis-read the question - I'll delete my answer! – David Wilkinson Feb 23 '16 at 09:20
-
@RaduDragan as above, I mis-read the question, I'll delete my answer. – David Wilkinson Feb 23 '16 at 09:20
1
Yes use higher z-index value for button than image. For more info refer this link
img{z-index:9;}
button{z-index:99;}

G.L.P
- 7,119
- 5
- 25
- 41
-
1But that doesn't set the image over the button then. EDIT: seeing screenshot, if elements get always being displayed that way, it could be a solution indeed – A. Wolff Feb 23 '16 at 09:15
-
-
-
-
-
-
i have no idear way is used http://www.isup.me/ and it`s telling me "it`s up", thanks – Radu Dragan Feb 23 '16 at 11:06
1
z-index property of css only works on positioned elements (position:absolute, position:relative, or position:fixed)
use this:
.imgclass {
position: relative; //or whatever you want i.e fixed
z-index: -1;
}
.buttonclass {
position: relative;
z-index: 999;
}

Ejaz47
- 145
- 1
- 12
-
-
1
-
you will not be able to click/hover the button because html elements are like stacks.... – Ejaz47 Feb 23 '16 at 09:35
-
you can see here way z-index this is not an answer http://fotodex.ro/constructor/test/ – Radu Dragan Feb 23 '16 at 09:59
-
[fotodex.ro/constructor/test/](http://fotodex.ro/constructor/test/) This web page is not available – Ejaz47 Feb 23 '16 at 10:07
1
As stated in the comments...without adjusting the z-index
of the image (which is apparently not an option) you are restricted to disabling pointer events on the image.
img {
pointer-events:none;
}
Support is all modern browsers but only IE11
Poor Demo:
body {
margin: 0;
padding: 0;
}
div {
height: 400px;
display: flex;
flex-direction: column;
}
button {
align-self: flex-start;
}
img {
opacity: 0.5;
position: relative;
top: -1em;
margin-left: 2em;
border: 1px solid red;
pointer-events: none;
}
<div>
<button>Click Me</button>
<img src="http://lorempixel.com/g/400/200/" alt="" />
</div>

Paulie_D
- 107,962
- 13
- 142
- 161