buboreka
buboreka

Reputation: 135

Png image as html button

I would like to use an icon as a drobdown button on my navbar, but I am new to html and stuff, so I do not know where my snipplet fails:

<button type= "image" class="dropbtn" onclick="myFunction()">
<img src="someimage.png" title="Some title">
</button>

Upvotes: 0

Views: 1238

Answers (3)

It is because the button image isnt linked to the href correctly and the "a" isnt closed correctly

I use:

<a href="link or image">
            <img src="yourimage.png">
        </a>

IT WORKS!!

Upvotes: 0

ilkovs
ilkovs

Reputation: 446

In your case the issue is most likely with the source of the image. Check the path (where your image is located) and link it correctly.

Example: src="../folder/folder/image.png"

You can also add the image as a background with CSS like this:

.dropbtn {
  background: url("");
}

Upvotes: 1

Vincenzo Carotenuto
Vincenzo Carotenuto

Reputation: 1

I think the problem is that you are using the button. Try this:

<a href="" class="dropbtn" onclick="myFunction()">
    <img src="someimage.png" title="Some title">
</a>

Upvotes: 0

Related Questions