Reputation: 741
Is it possible to position object/image over button in html? See the image below. The idea is to position object over button, but still make button fully operatable.
<button type="button" class="button">Place image on me</button>
How would I approach this?
Upvotes: 0
Views: 143
Reputation:
With the example below you can solve following promlems:
<div style="position:relative;">
<button onclick="alert('Hello');" style="position:absolute;top:30px;">Place image on me</button>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/34/Red_star.svg/252px-Red_star.svg.png" style="position:absolute;height:60px;left:40px;pointer-events:none;" />
</div>
You still need to adopt the styles to your needs because all is positioned with fixed pixel values for demo purposes.
Upvotes: 1
Reputation: 611
You can use image directly in button like this.
<button type="button" class="button">Place image on me <img src="#"/></button>
or use css if you don't want to use any html tag inside button and without resizing button with image.
.button {
position:relative;
}
.button:before {
content:"";
display:block;
background:url('img.png') no-repeat;
width:100px;
height:100px;
position:absolute;
}
Upvotes: 0
Reputation: 223
You can add images to the button itself by doing this:
<button type="button" class="button"><img src="#"/></button>
But if you will use the image to cover the button with css it won't work.
Upvotes: 0
Reputation: 141
<button type="button" class="button">Place image on me<img src="your-image.png"></button>
Upvotes: 0