Skip to content Skip to sidebar Skip to footer

Clickable Image Button

I'm trying to make an image clickable so that I can use it as a button to download a PDF although I feel like I'm over-thinking this and confusing myself. An example of the code I'

Solution 1:

So the problem you are facing is the the link (the <a> tag) is the actual button but that one has no size cause it's kind of empty. See this code snippet. The <a> tag has a red border all around but there is nothing which fills it up ...

#name {
  background-image: url(http://lorempixel.com/400/200/sports/1/);
  height: 51px;
  width: 285px;
  margin: auto;
  margin-bottom: 5px;
}

#name:hover {
  background-image: url(http://lorempixel.com/400/200/sports/2/);
  height: 51px;
  width: 285px;
  margin: auto;
  margin-bottom: 5px;
  cursor: pointer;
  -o-transition: .5s;
  -ms-transition: .5s;
  -moz-transition: .5s;
  -webkit-transition: .5s;
}

#namea {
    border:solid 1px red;
    background-color: orange;
    z-index: 999;
}
<divid="name"><ahref="#/path/to/file.pdf"></a></div>

So if you set all those styles you had to the <a> tag and add display: inline-block; then it will work see here:

#namea {
  display: inline-block; /* add this line */background-image: url(http://lorempixel.com/400/200/sports/1/);
  height: 51px;
  width: 285px;
  margin: auto;
  margin-bottom: 5px;
}

#namea:hover {
  background-image: url(http://lorempixel.com/400/200/sports/2/);
  height: 51px;
  width: 285px;
  margin: auto;
  margin-bottom: 5px;
  cursor: pointer;
  -o-transition: .5s;
  -ms-transition: .5s;
  -moz-transition: .5s;
  -webkit-transition: .5s;
}

#namea {
    border:solid 1px red;
    background-color: orange;
    z-index: 999;
}
<divid="name"><ahref="#/path/to/file.pdf"></a></div>

Post a Comment for "Clickable Image Button"