Link to home
Start Free TrialLog in
Avatar of Dan
DanFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to overlay text on a button with a background image

I have a button and I want to have a background image but then put text vertically centered in the button how can I place the text over the image. The code I have is:

<button class="dropbtn" style="width: 100% height: 20px; background-color: #D0D5E8; margin: 0px; padding: 0px;"><img  src="button-bg.png"></button>

This way the background gives it the style but the text will always be sharp as it is not being scaled.

Thanks,
Avatar of Sam Wallis
Sam Wallis

You want to add the background to the button via CSS not by adding an image.

Also, you didn't have ";" after the width which stopped all the other styles processing.

Here is the correct markup.  

<button class="dropbtn" style="width: 100%; height: 20px; background: url('button-bg.png') #D0D5E8; margin: 0px; padding: 0px;">
Button text
</button>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial