1

Is it possible to have a image (.png) over a button and still be able to click that button

enter image description here

  • 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 Answers4

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
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
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

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